[][src]Struct email_address_parser::EmailAddress

pub struct EmailAddress { /* fields omitted */ }

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]

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]

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]

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

impl IntoWasmAbi for EmailAddress[src]

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary. Read more

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

impl RefMutFromWasmAbi for EmailAddress[src]

type Abi = u32

Same as RefFromWasmAbi::Abi

type Anchor = RefMut<'static, EmailAddress>

Same as RefFromWasmAbi::Anchor

impl WasmDescribe for EmailAddress[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ReturnWasmAbi for T where
    T: IntoWasmAbi
[src]

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.