pub struct Email(/* private fields */);
Expand description
This crate provides a simple and efficient way to parse and validate email addresses.
§Example
use custom_type::Email;
let email = Email::parse("example@example.com").unwrap();
println!("{}", email);
§Features
- Parse and validate email addresses using a regular expression.
- Normalize email addresses to lowercase.
- Custom error type for handling invalid email addresses.
§Parse String To Valid Email
Call the parse()
method to parse impl ToString
into a valid email.
Implementations§
Source§impl Email
impl Email
Sourcepub fn parse(email: impl ToString) -> Result<Self, TypeError>
pub fn parse(email: impl ToString) -> Result<Self, TypeError>
Parses a given string into a valid email address.
§Arguments
email
- A string slice that holds the email address to be parsed.
§Returns
Ok(Self)
if the email is valid.Err(TypeError::ParseError)
if the email is invalid.
§Examples
use custom_type::Email;
let email = Email::parse("example@example.com");
assert!(email.is_ok());
let invalid_email = Email::parse("invalid-email");
assert!(invalid_email.is_err());
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Email
impl<'de> Deserialize<'de> for Email
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Email
Auto Trait Implementations§
impl Freeze for Email
impl RefUnwindSafe for Email
impl Send for Email
impl Sync for Email
impl Unpin for Email
impl UnwindSafe for Email
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more