Created
February 1, 2016 10:46
-
-
Save Keats/32d26f699dcc13ebd41b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Deserialize)] | |
pub struct SignupData { | |
#[validate(email)] | |
email: String, | |
// this would first run min_length and then call validate_unique_username | |
#[validate(min_length=2, custom=validate_unique_username)] | |
username: String, | |
#[validate(min_length=8, max_length=255)] | |
password: String, | |
} | |
pub fn validate_unique_username(username String) -> Option<Something> { | |
... | |
} | |
// And to use | |
// first basic serialization errors | |
let data: SignupData = serde_json::from_str(&serialized); | |
// then a magic method added () -> Option<ValidationError> with ValidationError being a hashmap | |
let errors = data.validate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment