Keats/validator

`required` and `must_match` are incompatible

Opened this issue · 2 comments

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>,
}

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

Keats commented

Someone would have to do a PR