Struct email_address_parser::EmailAddress[][src]

pub struct EmailAddress { /* fields omitted */ }
Expand description

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

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());

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))));

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);

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");

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more

Recover a Self from Self::Abi. Read more

Feeds this value into the given Hasher. Read more

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

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

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary. Read more

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi. Read more

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The wasm ABI type references to Self are recovered from.

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

Recover a Self::Anchor from Self::Abi. Read more

Same as RefFromWasmAbi::Abi

Same as RefFromWasmAbi::Anchor

Same as RefFromWasmAbi::ref_from_abi

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Same as IntoWasmAbi::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.