-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider using an existing rust validation library? #2
Comments
So I looked into the libraries and if I understand correctly, the flow is something like this: pub struct User{
#[validate(minimum = 0)]
#[validate(maximum = 120)] // users can be at most 120 years old
age: u8,
}
let user = User{age: 255}; // instantiate an invalid user
if let Err(err) = user.validate(){
# handle invalid value
} It's nice that we don't have to write the validation code ourselves, but it does come at a cost: Because this validation is not done at construction-time, it is possible to have invalid Still, what we have today might not be too different from that... Under I'll come back to this one |
Hmm I guess this is almost always going to be used for runtime validation - that's kinda the point of the library. The idea of enforcing compile-time validation, for the rare scenario where someone is hard-coding an RDF in rust... I'm not sure it made sense to spend time on that tbh 🤷 That said, you've done that now I guess. I'm still not 100% clear as to the utility... am testing now. |
I just tested your argument, and it does not really work as you had intentioned - see #3 |
See #3 |
When looking into the feasibility of this recently, I came across eg
validator
- https://crates.io/crates/validatorgarde
- https://crates.io/crates/gardeserde_valid
- https://crates.io/crates/serde_validPerhaps it would make more sense to use one of these for the "easy" fields and only worry about the more complicated validation logic ourselves - or is there a reason not to?
The text was updated successfully, but these errors were encountered: