Keats / validator

Simple validation for Rust structs
MIT License
1.94k stars 140 forks source link

`#[validate(...)]` helper attribute does not coexist with other helper attribute #340

Closed naskya closed 2 weeks ago

naskya commented 1 month ago

#[validate(...)] helper attribute does not coexist with other ident-only (#[foo]) helper attribute. The Test4 struct in the following code produces an compilation error.

// compiles
#[derive(Validate, Foo)]
struct Test1 {
    #[validate(nested)]
    a: A,
}

// compiles
#[derive(Validate, Foo)]
struct Test2 {
    #[validate(nested)]
    #[foo(foo)]
    a: A,
}

// compiles
#[derive(Validate, Foo)]
struct Test3 {
    #[validate(nested)]
    #[foo = "foo"]
    a: A,
}

// this does not compile
#[derive(Validate, Foo)]
struct Test4 {
    #[validate(nested)]
    #[foo]
    a: A,
}

#[derive(Validate)]
struct A {}

https://github.com/naskya/validator-helper-attribute-example/actions/runs/9945289199/job/27473203363

 error: You need to set at least one validator on field `a`

         = note: If you want nested validation, use `#[validate(nested)]`

  --> src/main.rs:26:5
   |
26 |     #[validate(nested)]
   |     ^

Anyway, thank you for maintaining this awesome project!

Keats commented 1 month ago

Looks like we might not be validating the name of the attribute?