serde_email/lib.rs
1//!
2//! This crate is for creating `Email` objects.
3//!
4//! * It allows you to have Email **as a type**. i.e. `let emails : Vec<Email> = vec![]`.
5//! * The `Email` type guarantees to be **structurally validated**. Once it is created, you can be confident it's safe to use as an email.
6//! * The `Email` type can also be **used as strings**. This allows interoptability with lots of connector functions which will take a String.
7//! * It **supports Serde** out of the box. For Serialisation with CLIs, requests, etc.
8//!
9//! (Note this library will not check if the Email address exists. It only validates that it looks correct.)
10//!
11//! ## Features
12//!
13//! * `serde` **Default** - Enables serde serialisation and deserialisation.
14//! * `sea-orm` - Enables Sea Orm use with DB entities.
15//!
16//! ## Usage
17//!
18//! ### Building your own email addresses
19//!
20//! ```rust
21//! use ::serde_email::Email;
22//!
23//! let email = Email::from_str("test@example.com").expect("A valid email address");
24//! ```
25//!
26//! ### Validating the email address yourself
27//!
28//! ```rust
29//! use ::serde_email::is_valid_email;
30//!
31//! if is_valid_email(&"test@example.com") {
32//! // do something
33//! }
34//! ```
35//!
36//! ### Serialisation / Deserialisation
37//!
38//! ```rust
39//! use ::serde_email::Email;
40//! use ::serde::Deserialize;
41//! use ::serde::Serialize;
42//! use ::serde_json;
43//!
44//! #[derive(Deserialize, Serialize)]
45//! struct Person {
46//! name: String,
47//! email: Email,
48//! }
49//!
50//! // Some JSON input data as a &str. Maybe this comes from the user.
51//! let data = r#"
52//! {
53//! "name": "John Doe",
54//! "email": "john@example.com"
55//! }"#;
56//!
57//! // Parse the string of data into serde_json::Value.
58//! let person: Person = serde_json::from_str(data).unwrap();
59//!
60//! // Access parts of the data by indexing with square brackets.
61//! println!("Hello {} I'll email you are {}", person.name, person.email);
62//! ```
63//!
64//! ### Sea Orm Entities
65//!
66//! You can use the `Email` type with Sea Orm, including using it to save data to the DB.
67//! Underneath it will serialise to a `Text` type within the DB.
68//!
69//! **Required**, the `sea-orm` feature must be enabled for Sea Orm support.
70//!
71//! ```rust
72//! use ::sea_orm::entity::prelude::*;
73//! use ::serde::Deserialize;
74//! use ::serde::Serialize;
75//! use ::serde_email::Email;
76//!
77//! #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
78//! #[sea_orm(table_name = "user")]
79//! pub struct Model {
80//! #[sea_orm(primary_key)]
81//! pub id: i32,
82//! pub email: Email, // use as an email field
83//! }
84//!
85//! #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
86//! pub enum Relation {}
87//!
88//! impl ActiveModelBehavior for ActiveModel {}
89//! ```
90//!
91
92mod email;
93pub use self::email::*;
94
95mod email_error;
96pub use self::email_error::*;
97
98mod is_valid_email;
99pub use self::is_valid_email::*;