Keats / validator

Simple validation for Rust structs
MIT License
1.98k stars 142 forks source link

must_match validator error #243

Closed odra closed 1 year ago

odra commented 1 year ago

Hello,

I am trying to use the must_match validator function based on what's documented in the readme file:

#[derive(Debug, Validate, Deserialize)]
pub struct Header {
    #[validate(must_match = "00")]
    pub register_type: String
}

Compling the above code leads to the following error:

error: Invalid argument for `must_match` validator of field `register_type`: the other field doesn't exist in struct
  --> src/lib/b3/equities/types/header.rs:13:5
   |
13 |     #[validate(must_match = "00")]
   |     ^

I tried other validator functions such as the regex one and it worked ok.

Am I missing something?

Validator version: 0.15

Keats commented 1 year ago

As mentioned in the docs (https://github.com/Keats/validator#must_match), must_match must refer to another field in the struct, not an arbitrary value. There is a regex validator in case you need to validate the content of a string