Email type for approach suggested by Alexis King - "Parse, don't validate".
Add dependency:
toml
email-type-rs = { git = "https://github.com/lebe-dev/email-type-rs", version = "1.0.0", features = ["utils"] }
Use:
```rust let email = Email::from_str("lexi.lambda@gmail.com")?; let email = "lexi.lambda@gmail.com".parse()?;
// fn somefunc(value: &str) somefunc(email.asstr()); somefunc(&email); ```
Useful for REST API Endpoints, i.e. /api/register
accepts:
```rust
struct UserRegistrationRequest { pub email: Email, ... } ```
Incoming JSON with invalid value in email
field will raise deserialization error (Serde).
Add to Cargo.toml
:
toml
[dev-dependencies]
email-type-rs = { git = "https://github.com/lebe-dev/email-type-rs", version = "1.0.0", features = ["utils"] }
Functions:
get_random_email()
- return random Email
. Useful for tests.