validity 0.1.1

Encode the validity of your data in the type system
Documentation

Encode the validity of your data in the type system

Example usage:

# use validity::*;
#[derive(Debug)]
struct Email(String);

impl Validate for Email {
type Error = ();

fn validate(&self) -> Result<(), Self::Error> {
// perform some actual email validation
Ok(()) 
}
}

// This requires a Valid<Email>, which guarantees the data has been validated
fn send_email(email: Valid<Email>) {
println!("Sending email to {:?}", email.0);
}

fn main() {
let email = Email("example@example.com".into()); 
let valid_email = Valid::new(email).unwrap();
// at this point, validation must have succeeded
send_email(valid_email);
}