pub struct Options {
pub minimum_sub_domains: usize,
pub allow_domain_literal: bool,
pub allow_display_text: bool,
}
Expand description
Struct of options that can be configured when parsing with parse_with_options
.
Fields§
§minimum_sub_domains: usize
Sets the minimum number of domain segments that must exist to parse successfully.
use email_address::*;
assert!(
EmailAddress::parse_with_options(
"simon@localhost",
Options::default().with_no_minimum_sub_domains(),
).is_ok()
);
assert_eq!(
EmailAddress::parse_with_options(
"simon@localhost",
Options::default().with_required_tld()
),
Err(Error::DomainTooFew)
);
allow_domain_literal: bool
Specifies if domain literals are allowed. Defaults to true
.
use email_address::*;
assert!(
EmailAddress::parse_with_options(
"email@[127.0.0.256]",
Options::default().with_domain_literal()
).is_ok()
);
assert_eq!(
EmailAddress::parse_with_options(
"email@[127.0.0.256]",
Options::default().without_domain_literal()
),
Err(Error::UnsupportedDomainLiteral),
);
allow_display_text: bool
Specified whether display text is allowed. Defaults to true
. If you want strict
email-only checking setting this to false
will remove support for the prefix string
and therefore the ‘<’ and ‘>’ brackets around the email part.
use email_address::*;
assert_eq!(
EmailAddress::parse_with_options(
"Simon <simon@example.com>",
Options::default().without_display_text()
),
Err(Error::UnsupportedDisplayName),
);
assert_eq!(
EmailAddress::parse_with_options(
"<simon@example.com>",
Options::default().without_display_text()
),
Err(Error::InvalidCharacter),
);
Implementations§
Source§impl Options
impl Options
Sourcepub const fn with_minimum_sub_domains(self, min: usize) -> Self
pub const fn with_minimum_sub_domains(self, min: usize) -> Self
Set the value of minimum_sub_domains
.
Sourcepub const fn with_no_minimum_sub_domains(self) -> Self
pub const fn with_no_minimum_sub_domains(self) -> Self
Set the value of minimum_sub_domains
to zero.
Sourcepub const fn with_required_tld(self) -> Self
pub const fn with_required_tld(self) -> Self
Set the value of minimum_sub_domains
to two, this has the effect of requiring a
domain name with a top-level domain (TLD).
Sourcepub const fn with_domain_literal(self) -> Self
pub const fn with_domain_literal(self) -> Self
Set the value of allow_domain_literal
to true
.
Sourcepub const fn without_domain_literal(self) -> Self
pub const fn without_domain_literal(self) -> Self
Set the value of allow_domain_literal
to false
.
Sourcepub const fn with_display_text(self) -> Self
pub const fn with_display_text(self) -> Self
Set the value of allow_display_text
to true
.
Sourcepub const fn without_display_text(self) -> Self
pub const fn without_display_text(self) -> Self
Set the value of allow_display_text
to false
.