[−][src]Struct email_address_parser::EmailAddress
Email address struct.
Examples
use email_address_parser::EmailAddress; assert!(EmailAddress::parse("foo@-bar.com", None).is_none()); let email = EmailAddress::parse("foo@bar.com", None); assert!(email.is_some()); let email = email.unwrap(); assert_eq!(email.get_local_part(), "foo"); assert_eq!(email.get_domain(), "bar.com"); assert_eq!(format!("{}", email), "foo@bar.com");
Implementations
impl EmailAddress
[src]
pub fn parse(
input: &str,
options: Option<ParsingOptions>
) -> Option<EmailAddress>
[src]
input: &str,
options: Option<ParsingOptions>
) -> Option<EmailAddress>
Parses a given string as an email address.
Accessible from WASM.
Returns Some(EmailAddress)
if the parsing is successful, else None
.
Examples
use email_address_parser::*; // strict parsing let email = EmailAddress::parse("foo@bar.com", None); assert!(email.is_some()); let email = email.unwrap(); assert_eq!(email.get_local_part(), "foo"); assert_eq!(email.get_domain(), "bar.com"); // non-strict parsing let email = EmailAddress::parse("\u{0d}\u{0a} \u{0d}\u{0a} test@iana.org", Some(ParsingOptions::new(true))); assert!(email.is_some()); // parsing invalid address let email = EmailAddress::parse("test@-iana.org", Some(ParsingOptions::new(true))); assert!(email.is_none()); let email = EmailAddress::parse("test@-iana.org", Some(ParsingOptions::new(true))); assert!(email.is_none()); let email = EmailAddress::parse("test", Some(ParsingOptions::new(true))); assert!(email.is_none()); let email = EmailAddress::parse("test", Some(ParsingOptions::new(true))); assert!(email.is_none());
pub fn is_valid(input: &str, options: Option<ParsingOptions>) -> bool
[src]
Validates if the given input
string is an email address or not.
Returns true
if the input
is valid, false
otherwise.
Unlike the parse
method, it does not instantiate an EmailAddress
.
Examples
use email_address_parser::*; // strict validation assert!(EmailAddress::is_valid("foo@bar.com", None)); // non-strict validation assert!(EmailAddress::is_valid("\u{0d}\u{0a} \u{0d}\u{0a} test@iana.org", Some(ParsingOptions::new(true)))); // invalid address assert!(!EmailAddress::is_valid("test@-iana.org", Some(ParsingOptions::new(true)))); assert!(!EmailAddress::is_valid("test@-iana.org", Some(ParsingOptions::new(true)))); assert!(!EmailAddress::is_valid("test", Some(ParsingOptions::new(true)))); assert!(!EmailAddress::is_valid("test", Some(ParsingOptions::new(true))));
impl EmailAddress
[src]
pub fn new(
local_part: &str,
domain: &str,
options: Option<ParsingOptions>
) -> Result<EmailAddress, String>
[src]
local_part: &str,
domain: &str,
options: Option<ParsingOptions>
) -> Result<EmailAddress, String>
Instantiates a new Some(EmailAddress)
for a valid local part and domain.
Returns Err
otherwise.
Examples
use email_address_parser::EmailAddress; let email = EmailAddress::new("foo", "bar.com", None).unwrap(); assert_eq!(EmailAddress::new("foo", "-bar.com", None).is_err(), true);
pub fn get_local_part(&self) -> &str
[src]
Returns the local part of the email address.
Not accessible from WASM.
Examples
use email_address_parser::EmailAddress; let email = EmailAddress::new("foo", "bar.com", None).unwrap(); assert_eq!(email.get_local_part(), "foo"); let email = EmailAddress::parse("foo@bar.com", None).unwrap(); assert_eq!(email.get_local_part(), "foo");
pub fn get_domain(&self) -> &str
[src]
Returns the domain of the email address.
Not accessible from WASM.
Examples
use email_address_parser::EmailAddress; let email = EmailAddress::new("foo", "bar.com", None).unwrap(); assert_eq!(email.get_domain(), "bar.com"); let email = EmailAddress::parse("foo@bar.com", None).unwrap(); assert_eq!(email.get_domain(), "bar.com");
Trait Implementations
impl Debug for EmailAddress
[src]
impl Display for EmailAddress
[src]
impl From<EmailAddress> for JsValue
[src]
fn from(value: EmailAddress) -> Self
[src]
impl FromWasmAbi for EmailAddress
[src]
type Abi = u32
The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more
unsafe fn from_abi(js: u32) -> Self
[src]
impl IntoWasmAbi for EmailAddress
[src]
type Abi = u32
The wasm ABI type that this converts into when crossing the ABI boundary. Read more
fn into_abi(self) -> u32
[src]
impl OptionFromWasmAbi for EmailAddress
[src]
impl OptionIntoWasmAbi for EmailAddress
[src]
impl RefFromWasmAbi for EmailAddress
[src]
type Abi = u32
The wasm ABI type references to Self
are recovered from.
type Anchor = Ref<'static, EmailAddress>
The type that holds the reference to Self
for the duration of the invocation of the function that has an &Self
parameter. This is required to ensure that the lifetimes don't persist beyond one function call, and so that they remain anonymous. Read more
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
[src]
impl RefMutFromWasmAbi for EmailAddress
[src]
type Abi = u32
Same as RefFromWasmAbi::Abi
type Anchor = RefMut<'static, EmailAddress>
Same as RefFromWasmAbi::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
[src]
impl WasmDescribe for EmailAddress
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
[src]
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,