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

required and must_match are incompatible #330

Open
jaw-sh opened this issue Jun 2, 2024 · 2 comments
Open

required and must_match are incompatible #330

jaw-sh opened this issue Jun 2, 2024 · 2 comments
Labels

Comments

@jaw-sh
Copy link

jaw-sh commented Jun 2, 2024

Version 0.18.1

Minimum demonstration.

#[derive(Debug, Deserialize, Default, Validate)]
pub struct XForm {
    #[validate(required)]
    pub a: Option<String>,
    #[validate(required, must_match(other = "a"))]
    pub b: Option<String>,
}

Error.

mismatched types
expected reference `&&std::string::String`
   found reference `&std::option::Option<std::string::String>`

must_match.rs(4, 8): function defined here

Removing required fixes this.

I have tried some cheeky workarounds, like removing required on just the second field, but that doesn't work. For instance, some combination of making one required and the other not required does not work. The following presents the same error.

#[derive(Debug, Deserialize, Default, Validate)]
pub struct XForm {
    #[validate(required, must_match(other = "b"))]
    pub a: Option<String>,
    pub b: Option<String>,
}


Edit: It actually appears that Options are totally incompatible, despite Option<T: Eq> generally working. This produces the same error.


#[derive(Debug, Deserialize, Default, Validate)]
pub struct XForm {
    #[validate(must_match(other = "b"))]
    pub a: Option<String>,
    pub b: Option<String>,
}
@Keats Keats added the bug label Jun 2, 2024
@clarnx
Copy link

clarnx commented Sep 14, 2024

I also experienced what @jaw-sh described. @Keats are there any plans to fix this?
Thanks.

@Keats
Copy link
Owner

Keats commented Sep 15, 2024

Someone would have to do a PR

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

No branches or pull requests

3 participants