| Crates.io | email-type-rs |
| lib.rs | email-type-rs |
| version | 1.0.1 |
| created_at | 2023-02-26 16:22:12.835579+00 |
| updated_at | 2023-02-26 17:06:42.9514+00 |
| description | Email type for 'parse, don't validate' approach |
| homepage | https://github.com/lebe-dev/email-type-rs |
| repository | https://github.com/lebe-dev/email-type-rs |
| max_upload_size | |
| id | 795280 |
| size | 7,068 |
Email type for approach suggested by Alexis King - "Parse, don't validate".
Add dependency:
email-type-rs = { git = "https://github.com/lebe-dev/email-type-rs", version = "1.0.0", features = ["utils"] }
Use:
let email = Email::from_str("lexi.lambda@gmail.com")?;
let email = "lexi.lambda@gmail.com".parse()?;
// fn some_func(value: &str)
some_func(email.as_str());
some_func(&email);
Useful for REST API Endpoints, i.e. /api/register accepts:
#[derive(Deserialize)]
struct UserRegistrationRequest {
pub email: Email,
...
}
Incoming JSON with invalid value in email field will raise deserialization error (Serde).
Add to Cargo.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.