Closed ollyde closed 4 months ago
Example
use serde_valid::Validate; #[derive(Serialize, Deserialize, Validate)] pub struct Input { #[validate(max_length = 55)] #[validate(max_length = 2)] pub name_update: Option<String> #[validate(max_length = 100)] #[validate(max_length = 5)] pub email_update: Option<String>, } /// Validate input object that extends Validate via serde_valid pub fn validate_input<T: Validate>(object_to_validate: &T) -> Result<(), Error> { match object_to_validate.validate() { Ok(_) => Ok(()), Err(e) => { eprintln!("Validation error: {0}", e); let error_message = format!("Validation error: {0}", e); // Some error } } }
This will fail since name is optional. There are many use cases for this.
Thanks!
Option is already supported.
See ok test case, and err test case.
If you expect different results from those test cases, please give me more information.
Example
This will fail since name is optional. There are many use cases for this.