Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the use of range validators restricted to primitive types? #204

Open
shugo256 opened this issue Apr 6, 2022 · 2 comments
Open

Why is the use of range validators restricted to primitive types? #204

shugo256 opened this issue Apr 6, 2022 · 2 comments

Comments

@shugo256
Copy link

shugo256 commented Apr 6, 2022

I wanted to use the range validator for my ordered enum type.

#[derive(Clone, Debug, PartialEq, PartialOrd)]
enum MyOrderedEnum { 
    First,
    Second,
    Third,
    Fourth,
}

#[derive(Validate)]
struct SecondOrThird {
    #[validate(range(
        min = "MyOrderedEnum::Second", 
        max = "MyOrderedEnum::Third"
    )]
    val: MyOrderedEnum
}

But I got the following error:

Validator `range` can only be used on number types but found `MyOrderedEnum` for field `val`

I noticed that this is explicitly checked with assert_has_range instead of letting the compiler check if the type implements PartialEq and PartialOrd.

I would like to know if there is any background to this or if it can be fixed.

Thank you.

@pintariching
Copy link
Contributor

Maybe this could be solved with #225?

@Keats
Copy link
Owner

Keats commented Aug 5, 2022

It might be possible yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants