pub struct ParsedDname { /* private fields */ }Expand description
A domain name parsed from a DNS message.
In an attempt to keep messages small, DNS uses a procedure called ‘name compression.’ It tries to minimize the space used for repeatedly appearing domain names by simply refering to the first occurence of the name. This works not only for complete names but also for suffixes. In this case, the first unique labels of the name are included and then a pointer is included for the rest of the name.
A consequence of this is that when parsing a domain name, its labels can be scattered all over the message and we would need to allocate some space to re-assemble the original name. However, in many cases we don’t need the complete name. Many operations can be performed by just iterating over the labels which we can do in place.
ParsedDname deals with such names. It takes a copy of Parser
representing the underlying DNS message and, if nedded, traverses over
the name starting at the current position of the parser. When being
created, the type quickly walks over the name to check that it is, indeed,
a valid name. While this does take a bit of time, it spares you having to
deal with possible parse errors later.
ParsedDname implementes the ToDname trait, so you can use it
everywhere where a generic absolute domain name is accepted. In
particular, you can compare it to other names or chain it to the end of a
relative name. If necessary, ToDname::to_name can be used to produce
a flat, self-contained Dname.
Implementations§
Source§impl ParsedDname
§Conversion
For a conversion into a regular Dname, see ToDname::to_name.
impl ParsedDname
§Conversion
For a conversion into a regular Dname, see ToDname::to_name.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Converts the name into a bytes value with its flat representation.
Source§impl ParsedDname
§Properties
impl ParsedDname
§Properties
Source§impl ParsedDname
§Working with Labels
impl ParsedDname
§Working with Labels
Sourcepub fn iter(&self) -> ParsedDnameIter<'_> ⓘ
pub fn iter(&self) -> ParsedDnameIter<'_> ⓘ
Returns an iterator over the labels of the name.
Sourcepub fn iter_suffixes(&self) -> ParsedSuffixIter ⓘ
pub fn iter_suffixes(&self) -> ParsedSuffixIter ⓘ
Returns an iterator over the suffixes of the name.
The returned iterator starts with the full name and then for each additional step returns a name with the left-most label stripped off until it reaches the root label.
Sourcepub fn label_count(&self) -> usize
pub fn label_count(&self) -> usize
Returns the number of labels in the domain name.
Sourcepub fn last(&self) -> &'static Label
pub fn last(&self) -> &'static Label
Returns a reference to the last label.
Because the last label in an absolute name is always the root label, this method can return a static reference. It is also a wee bit silly, but here for completeness.
Sourcepub fn starts_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
pub fn starts_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
Determines whether base is a prefix of self.
Sourcepub fn ends_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
pub fn ends_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
Determines whether base is a suffix of self.
Sourcepub fn split_first(&mut self) -> Option<RelativeDname>
pub fn split_first(&mut self) -> Option<RelativeDname>
Splits off the first label.
If this name is longer than just the root label, returns the first
label as a relative name and removes it from the name itself. If the
name is only the root label, returns None and does nothing.
Trait Implementations§
Source§impl Clone for ParsedDname
impl Clone for ParsedDname
Source§fn clone(&self) -> ParsedDname
fn clone(&self) -> ParsedDname
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Compose for ParsedDname
impl Compose for ParsedDname
Source§impl Compress for ParsedDname
impl Compress for ParsedDname
Source§impl Debug for ParsedDname
impl Debug for ParsedDname
Source§impl Display for ParsedDname
impl Display for ParsedDname
Source§impl Hash for ParsedDname
impl Hash for ParsedDname
Source§impl<'a> IntoIterator for &'a ParsedDname
impl<'a> IntoIterator for &'a ParsedDname
Source§impl Ord for ParsedDname
impl Ord for ParsedDname
Source§impl Parse for ParsedDname
impl Parse for ParsedDname
Source§fn skip(parser: &mut Parser) -> Result<(), Self::Err>
fn skip(parser: &mut Parser) -> Result<(), Self::Err>
Skip over a domain name.
This will only check the uncompressed part of the name. If the name is compressed but the compression pointer is invalid or the name pointed to is invalid or too long, the function will still succeed.
If you need to check that the name you are skipping over is valid, you
will have to use parse and drop the result.
Source§type Err = ParsedDnameError
type Err = ParsedDnameError
Source§impl ParseAll for ParsedDname
impl ParseAll for ParsedDname
Source§impl<N: ToDname> PartialEq<N> for ParsedDname
impl<N: ToDname> PartialEq<N> for ParsedDname
Source§impl<N: ToDname> PartialOrd<N> for ParsedDname
impl<N: ToDname> PartialOrd<N> for ParsedDname
Source§impl ToDname for ParsedDname
impl ToDname for ParsedDname
Source§impl<'a> ToLabelIter<'a> for ParsedDname
impl<'a> ToLabelIter<'a> for ParsedDname
Source§type LabelIter = ParsedDnameIter<'a>
type LabelIter = ParsedDnameIter<'a>
Source§fn iter_labels(&'a self) -> Self::LabelIter
fn iter_labels(&'a self) -> Self::LabelIter
Source§fn starts_with<N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
fn starts_with<N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
base is a prefix of self.