[−][src]Struct domain::base::name::ParsedDname
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]
Ref: Clone,
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]
Ref: OctetsRef,
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]
Ref: AsRef<[u8]>,
N: ToDname,
fn canonical_cmp(&self, other: &N) -> Ordering
[src]
#[must_use]fn canonical_lt(&self, other: &Rhs) -> bool
[src]
#[must_use]fn canonical_le(&self, other: &Rhs) -> bool
[src]
#[must_use]fn canonical_gt(&self, other: &Rhs) -> bool
[src]
#[must_use]fn canonical_ge(&self, other: &Rhs) -> bool
[src]
impl<Ref: Clone> Clone for ParsedDname<Ref>
[src]
fn clone(&self) -> ParsedDname<Ref>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Ref: AsRef<[u8]>> Compose for ParsedDname<Ref>
[src]
fn compose<T: OctetsBuilder>(&self, target: &mut T) -> Result<(), ShortBuf>
[src]
fn compose_canonical<T: OctetsBuilder>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
[src]
&self,
target: &mut T
) -> Result<(), ShortBuf>
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]
fn from(name: Dname<Ref>) -> ParsedDname<Ref>
[src]
impl<Ref: AsRef<[u8]>> Hash for ParsedDname<Ref>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<Ref: AsRef<[u8]>> Ord for ParsedDname<Ref>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<Ref> Parse<Ref> for ParsedDname<Ref> where
Ref: AsRef<[u8]> + Clone,
[src]
Ref: AsRef<[u8]> + Clone,
fn parse(parser: &mut Parser<Ref>) -> Result<Self, ParseError>
[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]
Ref: AsRef<[u8]>,
N: ToDname,
impl<Ref, N: ?Sized> PartialOrd<N> for ParsedDname<Ref> where
Ref: AsRef<[u8]>,
N: ToDname,
[src]
Ref: AsRef<[u8]>,
N: ToDname,
fn partial_cmp(&self, other: &N) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<Ref: AsRef<[u8]>> ToDname for ParsedDname<Ref>
[src]
fn as_flat_slice(&self) -> Option<&[u8]>
[src]
fn to_dname<Octets>(&self) -> Result<Dname<Octets>, PushError> where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: EmptyBuilder,
[src]
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: EmptyBuilder,
fn to_cow(&self) -> Dname<Cow<[u8]>>
[src]
fn to_vec(&self) -> Dname<Vec<u8>>
[src]
fn name_eq<N: ToDname + ?Sized>(&self, other: &N) -> bool
[src]
fn name_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
[src]
fn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
[src]
fn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
[src]
fn rrsig_label_count(&self) -> u8
[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
fn iter_labels(&'a self) -> Self::LabelIter
[src]
fn len(&self) -> usize
[src]
fn starts_with<N: ToLabelIter<'a> + ?Sized>(&'a self, base: &'a N) -> bool
[src]
fn ends_with<N: ToLabelIter<'a> + ?Sized>(&'a self, base: &'a N) -> bool
[src]
Auto Trait Implementations
impl<Ref> RefUnwindSafe for ParsedDname<Ref> where
Ref: RefUnwindSafe,
Ref: RefUnwindSafe,
impl<Ref> Send for ParsedDname<Ref> where
Ref: Send,
Ref: Send,
impl<Ref> Sync for ParsedDname<Ref> where
Ref: Sync,
Ref: Sync,
impl<Ref> Unpin for ParsedDname<Ref> where
Ref: Unpin,
Ref: Unpin,
impl<Ref> UnwindSafe for ParsedDname<Ref> where
Ref: UnwindSafe,
Ref: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,