pub struct Label(String);
Expand description
A domain name label, stored in lowercase in its ASCII-encoded form
Tuple Fields§
§0: String
Implementations§
Source§impl Label
impl Label
Sourcepub(crate) fn new_ace(label: String) -> Result<Self, ParseError>
pub(crate) fn new_ace(label: String) -> Result<Self, ParseError>
Create a new Label
from the given ACE input, checking if all
characters in the label are valid, and that the length is appropriate.
This function does not do any conversions, it only checks the input for
ASCII validity. The validity of A-labels is not checked and fake
A-labels (labels starting with “xn–”, while not being valid punycode)
are accepted.
§Errors
This function returns a ParseError
if parsing of the label fails
Sourcepub(crate) fn new_idn(label: &str) -> Result<Self, ParseError>
pub(crate) fn new_idn(label: &str) -> Result<Self, ParseError>
Create a new Label
from the given possibly-internationalized input
label, parsing and encoding the input into an A-label if necessary. If
the input contains a fake A-label, ParseError::Idna
is returned.
§Errors
This function returns a ParseError
if parsing of the label fails
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Get the internal string representing this label
The returned value is an ASCII lowercase string, with non-ASCII
characters encoded using punycode. The string does not contain any .
s.
It may however be a “fake A-label”, i.e. start with “xn–”, but
not be valid punycode.
§Example
let domain = Domain::presented("παράδειγμα.EXAMPLE.com")?;
for label in domain.labels() {
assert!(label.as_str().is_ascii());
assert!(label
.as_str()
.chars()
.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-'));
}