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]
impl<'a> ParsedDName<'a>
pub fn parse(parser: &mut Parser<'a>) -> ParseResult<Self>
[src]
pub 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.
pub fn unpack(&self) -> Cow<'a, DNameSlice>
[src]
pub 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.
pub fn as_slice(&self) -> Option<&'a DNameSlice>
[src]
pub fn as_slice(&self) -> Option<&'a DNameSlice>
Returns a slice if the name is uncompressed.
impl<'a> ParsedDName<'a>
[src]
impl<'a> ParsedDName<'a>
ⓘImportant traits for NameLabels<'a>pub fn labels(&self) -> NameLabels<'a>
[src]
pub fn labels(&self) -> NameLabels<'a>
Returns an iterator over the labels of the name.
ⓘImportant traits for NameLabelettes<'a>pub fn labelettes(&self) -> NameLabelettes<'a>
[src]
pub fn labelettes(&self) -> NameLabelettes<'a>
Returns an iterator over the labelettes of the name.
pub fn split_first(&self) -> Option<(&'a Label, Option<Self>)>
[src]
pub 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]
impl<'a> Clone for ParsedDName<'a>
fn clone(&self) -> 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[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a> DName for ParsedDName<'a>
[src]
impl<'a> DName for ParsedDName<'a>
fn to_cow(&self) -> Cow<DNameSlice>
[src]
fn to_cow(&self) -> Cow<DNameSlice>
Converts the name into an uncompressed name. Read more
ⓘImportant traits for NameLabels<'a>fn labels(&self) -> NameLabels
[src]
fn labels(&self) -> NameLabels
Returns an iterator over the labels of the domain name.
ⓘImportant traits for NameLabelettes<'a>fn labelettes(&self) -> NameLabelettes
[src]
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<()>
[src]
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<()>
[src]
fn compose_compressed<C: AsMut<Composer>>(
&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]
impl<'a, N: DName> PartialEq<N> for ParsedDName<'a>
fn eq(&self, other: &N) -> bool
[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[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<str> for ParsedDName<'a>
[src]
impl<'a> PartialEq<str> for ParsedDName<'a>
fn eq(&self, other: &str) -> bool
[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[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> Eq for ParsedDName<'a>
[src]
impl<'a> Eq for ParsedDName<'a>
impl<'a, N: DName> PartialOrd<N> for ParsedDName<'a>
[src]
impl<'a, N: DName> PartialOrd<N> for ParsedDName<'a>
fn partial_cmp(&self, other: &N) -> Option<Ordering>
[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[src]
fn lt(&self, other: &Rhs) -> bool
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[src]
fn le(&self, other: &Rhs) -> bool
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[src]
fn gt(&self, other: &Rhs) -> bool
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[src]
fn ge(&self, other: &Rhs) -> bool
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]
impl<'a> Ord for ParsedDName<'a>
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<'a> Hash for ParsedDName<'a>
[src]
impl<'a> Hash for ParsedDName<'a>
fn hash<H: Hasher>(&self, state: &mut H)
[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[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'a> Display for ParsedDName<'a>
[src]
impl<'a> Display for ParsedDName<'a>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a> Octal for ParsedDName<'a>
[src]
impl<'a> Octal for ParsedDName<'a>
impl<'a> LowerHex for ParsedDName<'a>
[src]
impl<'a> LowerHex for ParsedDName<'a>
impl<'a> UpperHex for ParsedDName<'a>
[src]
impl<'a> UpperHex for ParsedDName<'a>
impl<'a> Binary for ParsedDName<'a>
[src]
impl<'a> Binary for ParsedDName<'a>
impl<'a> Debug for ParsedDName<'a>
[src]
impl<'a> Debug for ParsedDName<'a>
Auto Trait Implementations
impl<'a> Send for ParsedDName<'a>
impl<'a> Send for ParsedDName<'a>
impl<'a> Sync for ParsedDName<'a>
impl<'a> Sync for ParsedDName<'a>