Keats / validator

Simple validation for Rust structs
MIT License
1.97k stars 141 forks source link

Return useful information #278

Open Alphapage opened 10 months ago

Alphapage commented 10 months ago

Hello,

It seems validate() only return () which is not very helpful. Is it possible to return the validator fields count ? It will then be possible to check if no validator was added to the struct and show an error for example in that case.

Thank you in advance for your answers.

Keats commented 10 months ago

I'm not sure it makes sense? With a function called validate I don't expect anything in particular in the Ok branch

Alphapage commented 10 months ago

Does it throw any error when no validation fields are added to the struct ?

Keats commented 10 months ago

why would it throw an error?

pintariching commented 10 months ago

I think they want the macro to throw an error if you have a struct with #[derive(Validate)] on it, but none of the fields have a #[validate] tag on it. I'm not sure how usefull this would be, but this could be a compile error instead.

Keats commented 10 months ago

A compile error would be fine but then you need to handle Validate with nested and check whether that other struct has some validation set up..