pub struct EmailAddress { /* private fields */ }Expand description
A parsed, validated, and normalized email address.
Immutable after construction. All accessors return borrowed data.
Implementations§
Source§impl EmailAddress
impl EmailAddress
Sourcepub fn parse_with(input: &str, config: &Config) -> Result<Self, Error>
pub fn parse_with(input: &str, config: &Config) -> Result<Self, Error>
Parse and validate with the given configuration.
Sourcepub fn local_part(&self) -> &str
pub fn local_part(&self) -> &str
The canonical local part (after normalization).
If subaddress stripping is enabled, this excludes the +tag.
If dot stripping is enabled, dots are removed.
Sourcepub fn tag(&self) -> Option<&str>
pub fn tag(&self) -> Option<&str>
The extracted subaddress tag, if present.
For user+promo@example.com, returns Some("promo").
Always extracted regardless of SubaddressPolicy — the policy only
affects whether it appears in canonical().
Sourcepub fn domain_unicode(&self) -> &str
pub fn domain_unicode(&self) -> &str
The canonical domain in Unicode form.
For internationalized domains (münchen.de → xn--mnchen-3ya.de),
returns the Unicode form of the canonical domain. For ASCII-only
domains, returns the same value as domain().
§Security
The Unicode form is intended for display only. It may reintroduce
IDN homograph attacks
where visually similar characters from different scripts produce
different domain names (e.g. Cyrillic а vs Latin a).
For security-sensitive comparisons (allow-lists, deduplication, access
control), always use domain() which returns the
ACE/Punycode form. If you must compare Unicode domains, apply your own
confusable-detection logic (see confusable_skeleton()).
use structured_email_address::EmailAddress;
let email: EmailAddress = "user@münchen.de".parse().unwrap();
assert_eq!(email.domain(), "xn--mnchen-3ya.de");
assert_eq!(email.domain_unicode(), "münchen.de");
let ascii: EmailAddress = "user@example.com".parse().unwrap();
assert_eq!(ascii.domain_unicode(), "example.com");Sourcepub fn display_name(&self) -> Option<&str>
pub fn display_name(&self) -> Option<&str>
The display name, if parsed from "Name" <addr> or Name <addr> format.
Sourcepub fn canonical(&self) -> String
pub fn canonical(&self) -> String
The full canonical address: local_part@domain.
If the local part contains characters that require quoting (spaces, special chars), it is wrapped in quotes for RFC compliance.
Sourcepub fn skeleton(&self) -> Option<&str>
pub fn skeleton(&self) -> Option<&str>
The confusable skeleton of the local part (if config enabled it).
Two addresses with the same skeleton + domain are visually confusable.
Sourcepub fn is_freemail(&self) -> bool
pub fn is_freemail(&self) -> bool
Check if the domain is a well-known freemail provider.
Sourcepub fn parse_batch(inputs: &[&str], config: &Config) -> Vec<Result<Self, Error>>
pub fn parse_batch(inputs: &[&str], config: &Config) -> Vec<Result<Self, Error>>
Parse a batch of email addresses with the given configuration.
Returns one Result per input, in the same order. The config is
shared across all inputs, amortizing setup cost.
§Example
use structured_email_address::{EmailAddress, Config};
let config = Config::default();
let results = EmailAddress::parse_batch(
&["alice@example.com", "invalid", "bob@example.org"],
&config,
);
assert!(results[0].is_ok());
assert!(results[1].is_err());
assert!(results[2].is_ok());Trait Implementations§
Source§impl Clone for EmailAddress
impl Clone for EmailAddress
Source§fn clone(&self) -> EmailAddress
fn clone(&self) -> EmailAddress
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EmailAddress
impl Debug for EmailAddress
Source§impl<'de> Deserialize<'de> for EmailAddress
Available on crate feature serde only.
impl<'de> Deserialize<'de> for EmailAddress
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for EmailAddress
impl Display for EmailAddress
Source§impl FromStr for EmailAddress
impl FromStr for EmailAddress
Source§impl Hash for EmailAddress
impl Hash for EmailAddress
Source§impl PartialEq for EmailAddress
Equality is based on canonical form (local_part + domain) only.
Display name, tag, and skeleton are intentionally excluded —
"John" <user@example.com> equals "Jane" <user@example.com>
because they route to the same mailbox.
impl PartialEq for EmailAddress
Equality is based on canonical form (local_part + domain) only.
Display name, tag, and skeleton are intentionally excluded —
"John" <user@example.com> equals "Jane" <user@example.com>
because they route to the same mailbox.
Source§impl Serialize for EmailAddress
Available on crate feature serde only.
impl Serialize for EmailAddress
serde only.