Keats / validator

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

Can no longer use multiple custom validations on one field with 0.17 #308

Closed divergentdave closed 3 months ago

divergentdave commented 4 months ago

I have some struct fields where I apply multiple custom validations. This worked in 0.16, but no longer works after the derive macro rewrite in 0.17. I now get the error message error: Duplicate field `custom`. Granted, I could create another custom validation function that composes the two, but I think this is an unnecessary burden to reuse of custom validations.

Keats commented 4 months ago

That should be added back

Keats commented 4 months ago

Ok that should be fixed in https://github.com/Keats/validator/pull/304

divergentdave commented 3 months ago

I think the fix in 0.18 is incomplete. If I comment out the can_validate_custom_fn_ok test in validator_derive_tests/tests/custom.rs, then rustc reports that valid_custom_fn() is unused. This indicates that, in the test can_validate_multiple_custom_fn_ok below, the first of two custom validators is ignored.

Keats commented 3 months ago

Argh, I guess it needs more tests

Keats commented 3 months ago

That's a facepalm worthy bug, you can see the diff above