Struct vos_core::EmailAddress
[−]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
impl EmailAddress
impl EmailAddress
pub fn new_unchecked(address: String) -> EmailAddress
pub fn new_unchecked(address: String) -> EmailAddress
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"));pub fn is_valid(address: &str) -> bool
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();pub fn is_valid_local_part(part: &str) -> bool
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.
pub fn is_valid_domain(part: &str) -> bool
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.
pub fn to_uri(&self) -> String
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")
);pub fn to_display(&self, display_name: &str) -> String
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>")
);pub fn local_part(&self) -> &str
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")
);Trait Implementations
impl AsRef<str> for EmailAddress
impl AsRef<str> for EmailAddress
impl Clone for EmailAddress
impl Clone for EmailAddress
fn clone(&self) -> EmailAddress
fn clone(&self) -> EmailAddress
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Debug for EmailAddress
impl Debug for EmailAddress
impl<'de> Deserialize<'de> for EmailAddress
impl<'de> Deserialize<'de> for EmailAddress
fn deserialize<D>(
deserializer: D
) -> Result<EmailAddress, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<EmailAddress, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Display for EmailAddress
impl Display for EmailAddress
impl FromStr for EmailAddress
impl FromStr for EmailAddress
type Err = Error
type Err = Error
fn from_str(s: &str) -> Result<EmailAddress, <EmailAddress as FromStr>::Err>
fn from_str(s: &str) -> Result<EmailAddress, <EmailAddress as FromStr>::Err>
s to return a value of this type. Read moreimpl Hash for EmailAddress
impl Hash for EmailAddress
impl PartialEq<EmailAddress> for EmailAddress
impl PartialEq<EmailAddress> for EmailAddress
fn eq(&self, other: &EmailAddress) -> bool
fn eq(&self, other: &EmailAddress) -> bool
impl Serialize for EmailAddress
impl Serialize for EmailAddress
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for EmailAddress
impl StructuralEq for EmailAddress
impl StructuralPartialEq for EmailAddress
Auto Trait Implementations
impl RefUnwindSafe for EmailAddress
impl Send for EmailAddress
impl Sync for EmailAddress
impl Unpin for EmailAddress
impl UnwindSafe for EmailAddress
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.