pub struct Name<Octs: ?Sized>(/* private fields */);
Expand description
An uncompressed, absolute domain name.
The type wraps an octets sequence that contains an absolute domain name in wire-format encoding. It provides an interface similar to a slice of the labels of the name, i.e., you can iterate over the labels, split them off, etc.
You can construct a domain name from a string via the FromStr
trait or
manually via a NameBuilder
. In addition, you can also parse it from
a message. This will, however, require the name to be uncompressed.
Otherwise, you would receive a ParsedName
which can be converted into
Name
via ToName::to_name
.
The canonical way to convert a domain name into its presentation format is
using to_string
or by using its Display
implementation (which
performs no allocations).
Implementations§
source§impl<Octs> Name<Octs>
impl<Octs> Name<Octs>
§Creating Values
sourcepub const unsafe fn from_octets_unchecked(octets: Octs) -> Self
pub const unsafe fn from_octets_unchecked(octets: Octs) -> Self
Creates a domain name from the underlying octets without any check.
Since this will allow to actually construct an incorrectly encoded domain name value, the function is unsafe.
§Safety
The octets sequence passed in octets
must contain a correctly
encoded absolute domain name. It must be at most 255 octets long.
It must contain the root label exactly once as its last label.
sourcepub fn from_octets(octets: Octs) -> Result<Self, NameError>
pub fn from_octets(octets: Octs) -> Result<Self, NameError>
Creates a domain name from an octet sequence.
This will only succeed if octets
contains a properly encoded
absolute domain name in wire format. Because the function checks for
correctness, this will take a wee bit of time.
pub fn from_symbols<Sym>(symbols: Sym) -> Result<Self, FromStrError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
Sym: IntoIterator<Item = Symbol>,
sourcepub fn from_chars<C>(chars: C) -> Result<Self, FromStrError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
C: IntoIterator<Item = char>,
pub fn from_chars<C>(chars: C) -> Result<Self, FromStrError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
C: IntoIterator<Item = char>,
Creates a domain name from a sequence of characters.
The sequence must result in a domain name in representation format. That is, its labels should be separated by dots. Actual dots, white space and backslashes should be escaped by a preceeding backslash, and any byte value that is not a printable ASCII character should be encoded by a backslash followed by its three digit decimal value.
If Internationalized Domain Names are to be used, the labels already need to be in punycode-encoded form.
The name will always be an absolute name. If the last character in the
sequence is not a dot, the function will quietly add a root label,
anyway. In most cases, this is likely what you want. If it isn’t,
though, use UncertainName
instead to be able to check.
sourcepub fn scan<S: Scanner<Name = Self>>(scanner: &mut S) -> Result<Self, S::Error>
pub fn scan<S: Scanner<Name = Self>>(scanner: &mut S) -> Result<Self, S::Error>
Reads a name in presentation format from the beginning of a scanner.
sourcepub fn root() -> Self
pub fn root() -> Self
Returns a domain name consisting of the root label only.
This function will work for any kind octets sequence that can be
created from an octets slice. Since this will require providing the
type parameter in some cases, there are shortcuts methods for specific
octets types: root_ref
, root_vec
, and root_bytes
.
sourcepub fn reverse_from_addr(addr: IpAddr) -> Result<Self, PushError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
pub fn reverse_from_addr(addr: IpAddr) -> Result<Self, PushError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
Creates a domain name for reverse IP address lookup.
The returned name will use the standard suffixes of in-addr.arpa.
for IPv4 addresses and ip6.arpa.
for IPv6.
source§impl Name<[u8]>
impl Name<[u8]>
sourcepub fn from_slice(slice: &[u8]) -> Result<&Self, NameError>
pub fn from_slice(slice: &[u8]) -> Result<&Self, NameError>
sourcepub fn root_slice() -> &'static Self
pub fn root_slice() -> &'static Self
Creates a domain name for the root label only atop an octets slice.
source§impl Name<Vec<u8>>
impl Name<Vec<u8>>
sourcepub fn vec_from_str(s: &str) -> Result<Self, FromStrError>
pub fn vec_from_str(s: &str) -> Result<Self, FromStrError>
Creates a domain name atop a Vec<u8>
from its string representation.
source§impl Name<Bytes>
impl Name<Bytes>
sourcepub fn root_bytes() -> Self
pub fn root_bytes() -> Self
Creates a domain name for the root label only atop a bytes values.
sourcepub fn bytes_from_str(s: &str) -> Result<Self, FromStrError>
pub fn bytes_from_str(s: &str) -> Result<Self, FromStrError>
Creates a domain name atop a Bytes from its string representation.
source§impl<Octs: ?Sized> Name<Octs>
impl<Octs: ?Sized> Name<Octs>
§Conversions
sourcepub fn as_octets(&self) -> &Octs
pub fn as_octets(&self) -> &Octs
Returns a reference to the underlying octets sequence.
These octets contain the domain name in wire format.
sourcepub fn into_octets(self) -> Octswhere
Octs: Sized,
pub fn into_octets(self) -> Octswhere
Octs: Sized,
Converts the domain name into the underlying octets sequence.
sourcepub fn into_relative(self) -> RelativeName<Octs>
pub fn into_relative(self) -> RelativeName<Octs>
Converts the name into a relative name by dropping the root label.
sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Returns a reference to the underlying octets slice.
The slice will contain the domain name in wire format.
sourcepub fn for_slice(&self) -> &Name<[u8]>
pub fn for_slice(&self) -> &Name<[u8]>
Returns a domain name for the octets slice of the content.
sourcepub fn make_canonical(&mut self)
pub fn make_canonical(&mut self)
Converts the domain name into its canonical form.
This will convert all octets that are upper case ASCII characters into their lower case equivalent.
source§impl<Octs: AsRef<[u8]> + ?Sized> Name<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> Name<Octs>
§Properties
sourcepub fn fmt_with_dot(&self) -> impl Display + '_
pub fn fmt_with_dot(&self) -> impl Display + '_
Returns an object that displays the name with a final dot.
The name itself displays without a final dot unless the name is the root label only. Because this means you can’t just unconditionally add a dot after the name, this method can be used to display the name always ending in a single dot.
source§impl<Octs: AsRef<[u8]> + ?Sized> Name<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> Name<Octs>
§Working with Labels
sourcepub fn iter_suffixes(&self) -> SuffixIter<'_, Octs>
pub fn iter_suffixes(&self) -> SuffixIter<'_, Octs>
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 + ?Sized>(&'a self, base: &'a N) -> bool
pub fn starts_with<'a, N: ToLabelIter + ?Sized>(&'a self, base: &'a N) -> bool
Determines whether base
is a prefix of self
.
sourcepub fn ends_with<'a, N: ToLabelIter + ?Sized>(&'a self, base: &'a N) -> bool
pub fn ends_with<'a, N: ToLabelIter + ?Sized>(&'a self, base: &'a N) -> bool
Determines whether base
is a suffix of self
.
sourcepub fn is_label_start(&self, index: usize) -> bool
pub fn is_label_start(&self, index: usize) -> bool
Returns whether an index points to the first byte of a non-root label.
sourcepub fn slice(&self, range: impl RangeBounds<usize>) -> &RelativeName<[u8]>
pub fn slice(&self, range: impl RangeBounds<usize>) -> &RelativeName<[u8]>
Returns the part of the name indicated by start and end positions.
The returned name will start at position begin
and end right before
position end
. Both positions are given as indexes into the
underlying octets sequence and must point to the begining of a label.
The method returns a reference to an unsized relative domain name and
is thus best suited for temporary referencing. If you want to keep the
part of the name around, range
is likely a better choice.
§Panics
The method panics if either position is not the start of a label or is out of bounds.
Because the returned domain name is relative, the method will also
panic if the end is equal to the length of the name. If you want to
slice the entire end of the name including the final root label, you
can use slice_from
instead.
sourcepub fn slice_from(&self, begin: usize) -> &Name<[u8]>
pub fn slice_from(&self, begin: usize) -> &Name<[u8]>
Returns the part of the name starting at the given position.
The returned name will start at the given postion and cover the
remainder of the name. The position begin
is provided as an index
into the underlying octets sequence and must point to the beginning
of a label.
The method returns a reference to an unsized domain name and
is thus best suited for temporary referencing. If you want to keep the
part of the name around, range_from
is likely a better choice.
§Panics
The method panics if begin
isn’t the index of the beginning of a
label or is out of bounds.
sourcepub fn range(
&self,
range: impl RangeBounds<usize>,
) -> RelativeName<<Octs as Octets>::Range<'_>>where
Octs: Octets,
pub fn range(
&self,
range: impl RangeBounds<usize>,
) -> RelativeName<<Octs as Octets>::Range<'_>>where
Octs: Octets,
Returns the part of the name indicated by start and end positions.
The returned name will start at position begin
and end right before
position end
. Both positions are given as indexes into the
underlying octets sequence and must point to the begining of a label.
§Panics
The method panics if either position is not the start of a label or is out of bounds.
Because the returned domain name is relative, the method will also
panic if the end is equal to the length of the name. If you
want to slice the entire end of the name including the final root
label, you can use range_from
instead.
sourcepub fn range_from(&self, begin: usize) -> Name<<Octs as Octets>::Range<'_>>where
Octs: Octets,
pub fn range_from(&self, begin: usize) -> Name<<Octs as Octets>::Range<'_>>where
Octs: Octets,
Returns the part of the name starting at the given position.
The returned name will start at the given postion and cover the
remainder of the name. The position begin
is provided as an index
into the underlying octets sequence and must point to the beginning
of a label.
§Panics
The method panics if begin
isn’t the index of the beginning of a
label or is out of bounds.
source§impl<Octs: AsRef<[u8]> + ?Sized> Name<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> Name<Octs>
sourcepub fn split(
&self,
mid: usize,
) -> (RelativeName<Octs::Range<'_>>, Name<Octs::Range<'_>>)where
Octs: Octets,
pub fn split(
&self,
mid: usize,
) -> (RelativeName<Octs::Range<'_>>, Name<Octs::Range<'_>>)where
Octs: Octets,
Splits the name into two at the given position.
Returns a pair of the left and right part of the split name.
§Panics
The method will panic if mid
is not the index of the beginning of
a label or if it is out of bounds.
sourcepub fn truncate(self, len: usize) -> RelativeName<Octs>
pub fn truncate(self, len: usize) -> RelativeName<Octs>
Truncates the name before len
.
Because truncating converts the name into a relative name, the method consumes self.
§Panics
The method will panic if len
is not the index of a new label or if
it is out of bounds.
sourcepub fn split_first(&self) -> Option<(&Label, Name<Octs::Range<'_>>)>where
Octs: Octets,
pub fn split_first(&self) -> Option<(&Label, Name<Octs::Range<'_>>)>where
Octs: Octets,
Splits off the first label.
If this name is longer than just the root label, returns a pair
of that label and the remaining name. If the name is only the root
label, returns None
.
sourcepub fn parent(&self) -> Option<Name<Octs::Range<'_>>>where
Octs: Octets,
pub fn parent(&self) -> Option<Name<Octs::Range<'_>>>where
Octs: Octets,
Returns the parent of the current name.
If the name consists of the root label only, returns None
.
sourcepub fn strip_suffix<N: ToName + ?Sized>(
self,
base: &N,
) -> Result<RelativeName<Octs>, Self>
pub fn strip_suffix<N: ToName + ?Sized>( self, base: &N, ) -> Result<RelativeName<Octs>, Self>
Strips the suffix base
from the domain name.
If base
is indeed a suffix, returns a relative domain name with the
remainder of the name. Otherwise, returns an error with an unmodified
self
.
Trait Implementations§
source§impl<Octs: AsRef<[u8]>> Borrow<Name<[u8]>> for Name<Octs>
impl<Octs: AsRef<[u8]>> Borrow<Name<[u8]>> for Name<Octs>
Borrow a domain name.
Containers holding an owned Name<_>
may be queried with name over a
slice. This Borrow<_>
impl supports user code querying containers with
compatible-but-different types like the following example:
use std::collections::HashMap;
use domain::base::Name;
fn get_description(
hash: &HashMap<Name<Vec<u8>>, String>
) -> Option<&str> {
let lookup_name: &Name<[u8]> =
Name::from_slice(b"\x03www\x07example\x03com\0").unwrap();
hash.get(lookup_name).map(|x| x.as_ref())
}
source§impl<Octs, N> CanonicalOrd<N> for Name<Octs>
impl<Octs, N> CanonicalOrd<N> for Name<Octs>
source§fn canonical_cmp(&self, other: &N) -> Ordering
fn canonical_cmp(&self, other: &N) -> Ordering
self
and other
.source§fn canonical_lt(&self, other: &Rhs) -> bool
fn canonical_lt(&self, other: &Rhs) -> bool
self
is canonically less than other
.source§fn canonical_le(&self, other: &Rhs) -> bool
fn canonical_le(&self, other: &Rhs) -> bool
self
is canonically less than or equal to other
.source§fn canonical_gt(&self, other: &Rhs) -> bool
fn canonical_gt(&self, other: &Rhs) -> bool
self
is canonically greater than other
.source§fn canonical_ge(&self, other: &Rhs) -> bool
fn canonical_ge(&self, other: &Rhs) -> bool
self
is canonically greater than or equal to other
.source§impl<L, R, Target> FlattenInto<Name<Target>> for Chain<L, R>where
L: ToRelativeName,
R: ToName + FlattenInto<Name<Target>, AppendError = BuilderAppendError<Target>>,
Target: FromBuilder,
<Target as FromBuilder>::Builder: EmptyBuilder,
impl<L, R, Target> FlattenInto<Name<Target>> for Chain<L, R>where
L: ToRelativeName,
R: ToName + FlattenInto<Name<Target>, AppendError = BuilderAppendError<Target>>,
Target: FromBuilder,
<Target as FromBuilder>::Builder: EmptyBuilder,
type AppendError = <<Target as FromBuilder>::Builder as OctetsBuilder>::AppendError
fn try_flatten_into(self) -> Result<Name<Target>, Self::AppendError>
source§impl<Octs, Target> FlattenInto<Name<Target>> for Name<Octs>where
Target: OctetsFrom<Octs>,
impl<Octs, Target> FlattenInto<Name<Target>> for Name<Octs>where
Target: OctetsFrom<Octs>,
type AppendError = <Target as OctetsFrom<Octs>>::Error
fn try_flatten_into(self) -> Result<Name<Target>, Self::AppendError>
source§impl<Octs, Target> FlattenInto<Name<Target>> for ParsedName<Octs>
impl<Octs, Target> FlattenInto<Name<Target>> for ParsedName<Octs>
type AppendError = <<Target as FromBuilder>::Builder as OctetsBuilder>::AppendError
fn try_flatten_into(self) -> Result<Name<Target>, Self::AppendError>
source§impl<Octets> From<Name<Octets>> for UncertainName<Octets>
impl<Octets> From<Name<Octets>> for UncertainName<Octets>
source§impl<Octs: AsRef<[u8]>> From<Name<Octs>> for ParsedName<Octs>
impl<Octs: AsRef<[u8]>> From<Name<Octs>> for ParsedName<Octs>
source§fn from(name: Name<Octs>) -> ParsedName<Octs>
fn from(name: Name<Octs>) -> ParsedName<Octs>
source§impl From<Name<SmallVec<[u8; 24]>>> for SearchList
impl From<Name<SmallVec<[u8; 24]>>> for SearchList
source§fn from(name: SearchSuffix) -> Self
fn from(name: SearchSuffix) -> Self
source§impl<Octs> FromStr for Name<Octs>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
impl<Octs> FromStr for Name<Octs>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses a string into an absolute domain name.
The name needs to be formatted in representation format, i.e., as a sequence of labels separated by dots. If Internationalized Domain Name (IDN) labels are to be used, these need to be given in punycode encoded form.
The implementation assumes that the string refers to an absolute name
whether it ends in a dot or not. If you need to be able to distinguish
between those two cases, you can use UncertainDname
instead.
source§type Err = FromStrError
type Err = FromStrError
source§impl<'a, Octs> IntoIterator for &'a Name<Octs>
impl<'a, Octs> IntoIterator for &'a Name<Octs>
source§impl<Octs, SrcOcts> OctetsFrom<Name<SrcOcts>> for Name<Octs>where
Octs: OctetsFrom<SrcOcts>,
impl<Octs, SrcOcts> OctetsFrom<Name<SrcOcts>> for Name<Octs>where
Octs: OctetsFrom<SrcOcts>,
source§impl<Octs: AsRef<[u8]> + ?Sized> Ord for Name<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> Ord for Name<Octs>
source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Returns the ordering between self
and other
.
Domain name order is determined according to the ‘canonical DNS name order’ as defined in section 6.1 of RFC 4034.
source§impl<Octs, N> PartialOrd<N> for Name<Octs>
impl<Octs, N> PartialOrd<N> for Name<Octs>
source§fn partial_cmp(&self, other: &N) -> Option<Ordering>
fn partial_cmp(&self, other: &N) -> Option<Ordering>
Returns the ordering between self
and other
.
Domain name order is determined according to the ‘canonical DNS name order’ as defined in section 6.1 of RFC 4034.
source§impl<Octs> ToLabelIter for Name<Octs>
impl<Octs> ToLabelIter for Name<Octs>
source§type LabelIter<'a> = NameIter<'a>
where
Octs: 'a
type LabelIter<'a> = NameIter<'a> where Octs: 'a
source§fn iter_labels(&self) -> Self::LabelIter<'_>
fn iter_labels(&self) -> Self::LabelIter<'_>
source§fn compose_len(&self) -> u16
fn compose_len(&self) -> u16
source§fn starts_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool
fn starts_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool
base
is a prefix of self
.source§impl<Octs: AsRef<[u8]> + ?Sized> ToName for Name<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> ToName for Name<Octs>
source§fn as_flat_slice(&self) -> Option<&[u8]>
fn as_flat_slice(&self) -> Option<&[u8]>
source§fn try_to_name<Octets>(
&self,
) -> Result<Name<Octets>, BuilderAppendError<Octets>>
fn try_to_name<Octets>( &self, ) -> Result<Name<Octets>, BuilderAppendError<Octets>>
source§fn to_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
fn to_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
source§fn try_to_canonical_name<Octets>(
&self,
) -> Result<Name<Octets>, BuilderAppendError<Octets>>
fn try_to_canonical_name<Octets>( &self, ) -> Result<Name<Octets>, BuilderAppendError<Octets>>
source§fn to_canonical_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
fn to_canonical_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
fn compose<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
fn compose_canonical<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
source§fn composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
fn composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
source§fn lowercase_composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
fn lowercase_composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
source§fn rrsig_label_count(&self) -> u8
fn rrsig_label_count(&self) -> u8
impl<Octs: AsRef<[u8]> + ?Sized> Eq for Name<Octs>
Auto Trait Implementations§
impl<Octs> Freeze for Name<Octs>
impl<Octs> RefUnwindSafe for Name<Octs>where
Octs: RefUnwindSafe + ?Sized,
impl<Octs> Send for Name<Octs>
impl<Octs> Sync for Name<Octs>
impl<Octs> Unpin for Name<Octs>
impl<Octs> UnwindSafe for Name<Octs>where
Octs: UnwindSafe + ?Sized,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)