pub struct EmailAddress(_);
Expand description

Type representing a single email address. This is basically a wrapper around a String, the email address is parsed for correctness with FromStr::from_str, which is the only want to create an instance. The various components of the email are not parsed out to be accessible independently.

Implementations§

source§

impl EmailAddress

source

pub fn new_unchecked<S>(address: S) -> EmailAddresswhere S: Into<String>,

Creates an EmailAddress without checking if the email is valid. Only call this method if the address is known to be valid.

use std::str::FromStr;
use email_address::EmailAddress;

let unchecked = "john.doe@example.com";
let email = EmailAddress::from_str(unchecked).expect("email is not valid");
let valid_email = String::from(email);
let email = EmailAddress::new_unchecked(valid_email);

assert_eq!("John Doe <john.doe@example.com>", email.to_display("John Doe"));
source

pub fn is_valid(address: &str) -> bool

Determine whether the address string is a valid email address. Note this is equivalent to the following:

use email_address::*;
use std::str::FromStr;

let is_valid = EmailAddress::from_str("johnstonskj@gmail.com").is_ok();
source

pub fn is_valid_local_part(part: &str) -> bool

Determine whether the part string would be a valid local-part if it were in an email address.

source

pub fn is_valid_domain(part: &str) -> bool

Determine whether the part string would be a valid domain if it were in an email address.

source

pub fn to_uri(&self) -> String

Return this email address formatted as a URI. This will also URI-encode the email address itself. So, name@example.org becomes mailto:name@example.org.

use email_address::*;
use std::str::FromStr;

assert_eq!(
    EmailAddress::from_str("name@example.org").unwrap().to_uri(),
    String::from("mailto:name@example.org")
);
source

pub fn to_display(&self, display_name: &str) -> String

Return a string formatted as a display email with the user name. This is commonly used in email headers and other locations where a display name is associated with the address.

use email_address::*;
use std::str::FromStr;

assert_eq!(
    EmailAddress::from_str("name@example.org").unwrap().to_display("My Name"),
    String::from("My Name <name@example.org>")
);
source

pub fn local_part(&self) -> &str

Returns the local part of the email address. This is borrowed so that no additional allocation is required.

use email_address::*;
use std::str::FromStr;

assert_eq!(
    EmailAddress::from_str("name@example.org").unwrap().local_part(),
    String::from("name")
);
source

pub fn domain(&self) -> &str

Returns the domain of the email address. This is borrowed so that no additional allocation is required.

use email_address::*;
use std::str::FromStr;

assert_eq!(
    EmailAddress::from_str("name@example.org").unwrap().domain(),
    String::from("example.org")
);
source

pub fn as_str(&self) -> &str

Returns the email address as a string reference.

Trait Implementations§

source§

impl AsRef<str> for EmailAddress

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for EmailAddress

source§

fn clone(&self) -> EmailAddress

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for EmailAddress

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for EmailAddress

source§

fn deserialize<D>( deserializer: D ) -> Result<EmailAddress, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for EmailAddress

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl FromStr for EmailAddress

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<EmailAddress, <EmailAddress as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for EmailAddress

source§

fn hash<H>(&self, state: &mut H)where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<EmailAddress> for EmailAddress

source§

fn eq(&self, other: &EmailAddress) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for EmailAddress

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for EmailAddress

source§

impl StructuralEq for EmailAddress

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,