Struct domain::bits::name::ParsedDName
[−]
[src]
pub struct ParsedDName<'a> { /* fields omitted */ }
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 repeated 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 message. Many operations can be completed by just iterating over the labels which we can do in place.
This is what the ParsedDName
type does: It takes a reference to a
message and an indicator where inside the message the name starts and
then walks over the message as necessity dictates. When created while
parsing a message, the parser quickly walks over the labels to make sure
that the name indeed is valid. While this takes up a bit of time, it
avoids late surprises and provides for a nicer interface with less
Result
s.
Obviously, ParsedDName
implements the DName
trait and provides all
operations required by this trait. It also implements PartialEq
and
Eq
, as well as PartialOrd
and Ord
against all other domain name
types, plus Hash
with the same as the other types.
Methods
impl<'a> ParsedDName<'a>
[src]
fn parse(parser: &mut Parser<'a>) -> ParseResult<Self>
Creates a new parsed domain name.
This parses out the leading uncompressed labels from the parser and then quickly jumps over any possible remaining compressing to check that the name is valid.
fn unpack(&self) -> Cow<'a, DNameSlice>
Unpacks the name.
This will return the cow’s borrowed variant for any parsed name that isn’t in fact compressed. Otherwise it will assemble all the labels into an owned domain name.
fn as_slice(&self) -> Option<&'a DNameSlice>
Returns a slice if the name is uncompressed.
impl<'a> ParsedDName<'a>
[src]
fn labels(&self) -> NameLabels<'a>
Returns an iterator over the labels of the name.
fn labelettes(&self) -> NameLabelettes<'a>
Returns an iterator over the labelettes of the name.
fn split_first(&self) -> Option<(&'a Label, Option<Self>)>
Splits off the first label from the name.
For correctly encoded names, this function will always return
Some(_)
. The first element will be the parsed out label. The
second element will be a parsed name of the remainder of the name
if the label wasn’t the root label or None
otherwise.
Trait Implementations
impl<'a> Clone for ParsedDName<'a>
[src]
fn clone(&self) -> ParsedDName<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'a> DName for ParsedDName<'a>
[src]
fn to_cow(&self) -> Cow<DNameSlice>
Converts the name into an uncompressed name. Read more
fn labels(&self) -> NameLabels
Returns an iterator over the labels of the domain name.
fn labelettes(&self) -> NameLabelettes
Returns an iterator over the labelettes of the domain name. Read more
fn compose<C: AsMut<Composer>>(&self, composer: C) -> ComposeResult<()>
Appends the name to the end of a composition.
fn compose_compressed<C: AsMut<Composer>>(
&self,
composer: C
) -> ComposeResult<()>
&self,
composer: C
) -> ComposeResult<()>
Appends the name to the end of a composition using name compression.
impl<'a, N: DName> PartialEq<N> for ParsedDName<'a>
[src]
fn eq(&self, other: &N) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<'a> PartialEq<str> for ParsedDName<'a>
[src]
fn eq(&self, other: &str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<'a> Eq for ParsedDName<'a>
[src]
impl<'a, N: DName> PartialOrd<N> for ParsedDName<'a>
[src]
fn partial_cmp(&self, other: &N) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'a> Ord for ParsedDName<'a>
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
ord_max_min
)Compares and returns the minimum of two values. Read more
impl<'a> Hash for ParsedDName<'a>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more