Email type
Email type for approach suggested by Alexis King - "Parse, don't validate".
How to use:
Add dependency:
= { = "https://github.com/lebe-dev/email-type-rs", = "1.0.0", = ["utils"] }
Use:
let email = from_str?;
let email = "lexi.lambda@gmail.com".parse?;
// fn some_func(value: &str)
some_func;
some_func;
Useful for REST API Endpoints, i.e. /api/register accepts:
Incoming JSON with invalid value in email field will raise deserialization error (Serde).
Util functions
Add to Cargo.toml:
[]
= { = "https://github.com/lebe-dev/email-type-rs", = "1.0.0", = ["utils"] }
Functions:
get_random_email()- return randomEmail. Useful for tests.
Thanks
- Alexis King, article - Parse, don't validate
- Justin Wernick, article - The Newtype Pattern In Rust