pub struct ProviderRule { /* private fields */ }Expand description
Normalization rule for one mail provider (a set of equivalent domains).
Construct with ProviderRule::new and refine with the builder-style
setters. Fields are private so the rule can gain options without a breaking
change.
§Example
use structured_email_address::ProviderRule;
// A corporate provider that ignores dots and folds case, tag separator '+'.
let rule = ProviderRule::new(["mail.example.com"])
.strip_dots(true)
.lowercase_local(true)
.freemail(false);
assert!(rule.matches("MAIL.EXAMPLE.COM"));Implementations§
Source§impl ProviderRule
impl ProviderRule
Sourcepub fn new<I, S>(domains: I) -> Self
pub fn new<I, S>(domains: I) -> Self
Create a rule for the given domains.
Domains are stored in their IDNA-ASCII (punycode) canonical form so a
rule registered as münchen.de and one as xn--mnchen-3ya.de are
equivalent, and matching agrees with the canonical domain used elsewhere.
Defaults: no dot stripping, no case folding, + subaddress separator,
and is_freemail = false (a custom rule is treated as a private domain
unless you opt in with freemail(true)).
Sourcepub fn strip_dots(self, yes: bool) -> Self
pub fn strip_dots(self, yes: bool) -> Self
Set whether dots in the local part are insignificant (e.g. Gmail).
Sourcepub fn lowercase_local(self, yes: bool) -> Self
pub fn lowercase_local(self, yes: bool) -> Self
Set whether the local part is case-insensitive (folded to lowercase).
Sourcepub fn subaddress_separator(self, sep: Option<char>) -> Self
pub fn subaddress_separator(self, sep: Option<char>) -> Self
Set the subaddress separator, or None if the provider has no
subaddressing.
Sourcepub fn matches(&self, domain: &str) -> bool
pub fn matches(&self, domain: &str) -> bool
Returns true if domain belongs to this provider.
The domain is canonicalized to IDNA-ASCII before comparison, so Unicode and punycode spellings of the same domain match.
Sourcepub fn strips_dots(&self) -> bool
pub fn strips_dots(&self) -> bool
Whether the local part’s dots are insignificant.
Sourcepub fn folds_case(&self) -> bool
pub fn folds_case(&self) -> bool
Whether the local part is case-insensitive.
Sourcepub fn is_freemail(&self) -> bool
pub fn is_freemail(&self) -> bool
Whether this is a free webmail provider.
Trait Implementations§
Source§impl Clone for ProviderRule
impl Clone for ProviderRule
Source§fn clone(&self) -> ProviderRule
fn clone(&self) -> ProviderRule
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more