[][src]Struct domain::base::ParsedDname

pub struct ParsedDname<Ref> { /* 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 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 remainder 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 a Parser representing a reference to 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 on.

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

impl<Ref> ParsedDname<Ref>[src]

pub fn is_compressed(&self) -> bool[src]

Returns whether the name is compressed.

pub fn is_root(&self) -> bool[src]

Returns whether the name is the root label only.

impl<Ref: AsRef<[u8]>> ParsedDname<Ref>[src]

pub fn iter(&self) -> ParsedDnameIter[src]

Returns an iterator over the labels of the name.

pub fn iter_suffixes(&self) -> ParsedSuffixIter<Ref> where
    Ref: Clone
[src]

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.

pub fn label_count(&self) -> usize[src]

Returns the number of labels in the domain name.

pub fn first(&self) -> &Label[src]

Returns a reference to the first label.

pub fn last(&self) -> &'static Label[src]

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.

pub fn starts_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool[src]

Determines whether base is a prefix of self.

pub fn ends_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool[src]

Determines whether base is a suffix of self.

pub fn split_first(&mut self) -> Option<RelativeDname<Ref::Range>> where
    Ref: OctetsRef
[src]

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.

pub fn parent(&mut self) -> bool[src]

Reduces the name to the parent of the current name.

If the name consists of the root label only, returns false and does nothing. Otherwise, drops the first label and returns true.

Trait Implementations

impl<Ref, N: ?Sized> CanonicalOrd<N> for ParsedDname<Ref> where
    Ref: AsRef<[u8]>,
    N: ToDname
[src]

impl<Ref: Clone> Clone for ParsedDname<Ref>[src]

impl<Ref: AsRef<[u8]>> Compose for ParsedDname<Ref>[src]

impl<Ref: Copy> Copy for ParsedDname<Ref>[src]

impl<Ref: AsRef<[u8]>> Debug for ParsedDname<Ref>[src]

impl<Ref: AsRef<[u8]>> Display for ParsedDname<Ref>[src]

fn fmt(&self, f: &mut Formatter) -> Result[src]

Formats the domain name.

This will produce the domain name in common display format without the trailing dot.

impl<Ref: AsRef<[u8]>> Eq for ParsedDname<Ref>[src]

impl<Ref: AsRef<[u8]>> From<Dname<Ref>> for ParsedDname<Ref>[src]

impl<Ref: AsRef<[u8]>> Hash for ParsedDname<Ref>[src]

impl<'a, Ref: AsRef<[u8]>> IntoIterator for &'a ParsedDname<Ref>[src]

type Item = &'a Label

The type of the elements being iterated over.

type IntoIter = ParsedDnameIter<'a>

Which kind of iterator are we turning this into?

impl<Ref: AsRef<[u8]>> Ord for ParsedDname<Ref>[src]

impl<Ref> Parse<Ref> for ParsedDname<Ref> where
    Ref: AsRef<[u8]> + Clone
[src]

fn skip(parser: &mut Parser<Ref>) -> Result<(), ParseError>[src]

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.

impl<Ref, N: ?Sized> PartialEq<N> for ParsedDname<Ref> where
    Ref: AsRef<[u8]>,
    N: ToDname
[src]

impl<Ref, N: ?Sized> PartialOrd<N> for ParsedDname<Ref> where
    Ref: AsRef<[u8]>,
    N: ToDname
[src]

impl<Ref: AsRef<[u8]>> ToDname for ParsedDname<Ref>[src]

impl<'a, Ref: AsRef<[u8]>> ToLabelIter<'a> for ParsedDname<Ref>[src]

type LabelIter = ParsedDnameIter<'a>

The type of the iterator over the labels. Read more

Auto Trait Implementations

impl<Ref> RefUnwindSafe for ParsedDname<Ref> where
    Ref: RefUnwindSafe

impl<Ref> Send for ParsedDname<Ref> where
    Ref: Send

impl<Ref> Sync for ParsedDname<Ref> where
    Ref: Sync

impl<Ref> Unpin for ParsedDname<Ref> where
    Ref: Unpin

impl<Ref> UnwindSafe for ParsedDname<Ref> where
    Ref: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,