Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
pub struct SignupData {
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