This crate is for creating Email
objects.
let emails : Vec<Email> = vec![]
.Email
type guarantees to be validated. Once it is created, you can be confident it's safe to use as an email.Email
type can also be used as strings. This allows interoptability with lots of connector functions which will take a String.```rust use ::emailio::Email;
let email = Email::new("test@example.com".to_string()).expect("A valid email address"); ```
```rust use ::emailio::isvalidemail;
if isvalidemail(&"test@example.com") { // do something } ```
```rust use ::emailio::Email; use ::serde_json;
struct Person {
name: String,
email: Email,
}
// Some JSON input data as a &str. Maybe this comes from the user.
let data = r#"
{
"name": "John Doe",
"email": "john@example.com"
}"#;
// Parse the string of data into serde_json::Value.
let person: Person = serde_json::from_str(data).unwrap();
// Access parts of the data by indexing with square brackets.
println!("Hello {} I'll email you are {}", person.name, person.email);
```
serde
- Enables serde serialisation and deserialisation. On by default.The validation is all done by the email_address crate.