Struct domain::base::name::RelativeDname
source · pub struct RelativeDname<Octs: ?Sized>(_);
Expand description
An uncompressed, relative domain name.
A relative domain name is one that doesn’t end with the root label. As the
name suggests, it is relative to some other domain name. This type wraps
a octets sequence containing such a relative name similarly to the way
Dname
wraps an absolute one. In fact, it behaves very similarly to
Dname
taking into account differences when slicing and dicing names.
RelativeDname
guarantees that the name is at most 254 bytes long. As the
length limit for a domain name is actually 255 bytes, this means that you
can always safely turn a RelativeDname
into a Dname
by adding the root
label (which is exactly one byte long).
Implementations§
source§impl<Octs> RelativeDname<Octs>
impl<Octs> RelativeDname<Octs>
sourcepub const unsafe fn from_octets_unchecked(octets: Octs) -> Self
pub const unsafe fn from_octets_unchecked(octets: Octs) -> Self
Creates a relative domain name from octets without checking.
Since the content of the octets sequence can be anything, really, this is an unsafe function.
Safety
The octets sequence passed via octets
must contain a correctly
encoded relative domain name. It must be at most 254 octets long.
There must be no root labels anywhere in the name.
sourcepub fn from_octets(octets: Octs) -> Result<Self, RelativeDnameError>where
Octs: AsRef<[u8]>,
pub fn from_octets(octets: Octs) -> Result<Self, RelativeDnameError>where Octs: AsRef<[u8]>,
Creates a relative domain name from an octets sequence.
This checks that octets
contains a properly encoded relative domain
name and fails if it doesn’t.
sourcepub fn wildcard() -> Selfwhere
Octs: From<&'static [u8]>,
pub fn wildcard() -> Selfwhere Octs: From<&'static [u8]>,
Creates a relative domain name representing the wildcard label.
The wildcard label is intended to match any label. There are special rules for names with wildcard labels. Note that the comparison traits implemented for domain names do not consider wildcards and treat them as regular labels.
sourcepub fn from_chars<C>(chars: C) -> Result<Self, RelativeFromStrError>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, RelativeFromStrError>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.
source§impl RelativeDname<[u8]>
impl RelativeDname<[u8]>
sourcepub fn from_slice(slice: &[u8]) -> Result<&Self, RelativeDnameError>
pub fn from_slice(slice: &[u8]) -> Result<&Self, RelativeDnameError>
Creates a relative domain name from an octet slice.
Note that the input must be in wire format, as shown below.
Example
use domain::base::name::RelativeDname;
RelativeDname::from_slice(b"\x0c_submissions\x04_tcp");
sourcepub fn empty_slice() -> &'static Self
pub fn empty_slice() -> &'static Self
Returns an empty relative name atop a unsized slice.
pub fn wildcard_slice() -> &'static Self
source§impl RelativeDname<&'static [u8]>
impl RelativeDname<&'static [u8]>
sourcepub fn wildcard_ref() -> Self
pub fn wildcard_ref() -> Self
Creates a wildcard relative name atop a slice reference.
source§impl RelativeDname<Vec<u8>>
impl RelativeDname<Vec<u8>>
sourcepub fn wildcard_vec() -> Self
pub fn wildcard_vec() -> Self
Creates a wildcard relative name atop a Vec<u8>
.
sourcepub fn vec_from_str(s: &str) -> Result<Self, RelativeFromStrError>
pub fn vec_from_str(s: &str) -> Result<Self, RelativeFromStrError>
Parses a string into a relative name atop a Vec<u8>
.
source§impl RelativeDname<Bytes>
impl RelativeDname<Bytes>
sourcepub fn empty_bytes() -> Self
pub fn empty_bytes() -> Self
Creates an empty relative name atop a bytes value.
sourcepub fn wildcard_bytes() -> Self
pub fn wildcard_bytes() -> Self
Creates a wildcard relative name atop a bytes value.
sourcepub fn bytes_from_str(s: &str) -> Result<Self, RelativeFromStrError>
pub fn bytes_from_str(s: &str) -> Result<Self, RelativeFromStrError>
Parses a string into a relative name atop a Bytes
.
source§impl<Octs: ?Sized> RelativeDname<Octs>
impl<Octs: ?Sized> RelativeDname<Octs>
sourcepub fn into_octets(self) -> Octswhere
Octs: Sized,
pub fn into_octets(self) -> Octswhere Octs: Sized,
Converts the name into the underlying octets.
sourcepub fn for_ref(&self) -> RelativeDname<&Octs>
pub fn for_ref(&self) -> RelativeDname<&Octs>
Returns a domain name using a reference to the octets.
sourcepub fn as_slice(&self) -> &[u8] ⓘwhere
Octs: AsRef<[u8]>,
pub fn as_slice(&self) -> &[u8] ⓘwhere Octs: AsRef<[u8]>,
Returns a reference to an octets slice with the content of the name.
sourcepub fn for_slice(&self) -> &RelativeDname<[u8]>where
Octs: AsRef<[u8]>,
pub fn for_slice(&self) -> &RelativeDname<[u8]>where Octs: AsRef<[u8]>,
Returns a domain name for the octets slice of the content.
sourcepub fn make_canonical(&mut self)where
Octs: AsMut<[u8]>,
pub fn make_canonical(&mut self)where Octs: AsMut<[u8]>,
Converts the name into its canonical form.
source§impl<Octs> RelativeDname<Octs>
impl<Octs> RelativeDname<Octs>
sourcepub fn into_builder(self) -> DnameBuilder<<Octs as IntoBuilder>::Builder>where
Octs: IntoBuilder,
pub fn into_builder(self) -> DnameBuilder<<Octs as IntoBuilder>::Builder>where Octs: IntoBuilder,
Converts the name into a domain name builder for appending data.
This method is only available for octets sequences that have an
associated octets builder such as Vec<u8>
or Bytes
.
sourcepub fn into_absolute(self) -> Result<Dname<Octs>, PushError>where
Octs: IntoBuilder,
<Octs as IntoBuilder>::Builder: FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
pub fn into_absolute(self) -> Result<Dname<Octs>, PushError>where Octs: IntoBuilder, <Octs as IntoBuilder>::Builder: FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
Converts the name into an absolute name by appending the root label.
This manipulates the name itself and thus is only available for
octets sequences that can be converted into an octets builder and back
such as Vec<u8>
.
sourcepub fn chain<N: ToLabelIter>(
self,
other: N
) -> Result<Chain<Self, N>, LongChainError>where
Octs: AsRef<[u8]>,
pub fn chain<N: ToLabelIter>( self, other: N ) -> Result<Chain<Self, N>, LongChainError>where Octs: AsRef<[u8]>,
Chains another name to the end of this name.
Depending on whether other
is an absolute or relative domain name,
the resulting name will behave like an absolute or relative name.
The method will fail if the combined length of the two names is
greater than the size limit of 255. Note that in this case you will
loose both self
and other
, so it might be worthwhile to check
first.
source§impl<Octs: AsRef<[u8]> + ?Sized> RelativeDname<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> RelativeDname<Octs>
sourcepub fn label_count(&self) -> usize
pub fn label_count(&self) -> usize
Returns the number of labels in the name.
sourcepub fn first(&self) -> Option<&Label>
pub fn first(&self) -> Option<&Label>
Returns a reference to the first label if the name isn’t empty.
sourcepub fn last(&self) -> Option<&Label>
pub fn last(&self) -> Option<&Label>
Returns a reference to the last label if the name isn’t empty.
sourcepub fn ndots(&self) -> usize
pub fn ndots(&self) -> usize
Returns the number of dots in the string representation of the name.
Specifically, returns a value equal to the number of labels minus one, except for an empty name where it returns a zero, also.
sourcepub fn starts_with<N: ToLabelIter>(&self, base: &N) -> bool
pub fn starts_with<N: ToLabelIter>(&self, base: &N) -> bool
Determines whether base
is a prefix of self
.
sourcepub fn ends_with<N: ToLabelIter>(&self, base: &N) -> bool
pub fn ends_with<N: ToLabelIter>(&self, base: &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 octet of a label.
sourcepub fn slice(&self, range: impl RangeBounds<usize>) -> &RelativeDname<[u8]>
pub fn slice(&self, range: impl RangeBounds<usize>) -> &RelativeDname<[u8]>
Returns a 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 beginning of a label or is out of bounds.
sourcepub fn range(
&self,
range: impl RangeBounds<usize>
) -> RelativeDname<<Octs as Octets>::Range<'_>>where
Octs: Octets,
pub fn range( &self, range: impl RangeBounds<usize> ) -> RelativeDname<<Octs as Octets>::Range<'_>>where Octs: Octets,
Returns a 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 beginning of a label or is out of bounds.
source§impl<Octs: AsRef<[u8]> + ?Sized> RelativeDname<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> RelativeDname<Octs>
sourcepub fn split(
&self,
mid: usize
) -> (RelativeDname<Octs::Range<'_>>, RelativeDname<Octs::Range<'_>>)where
Octs: Octets,
pub fn split( &self, mid: usize ) -> (RelativeDname<Octs::Range<'_>>, RelativeDname<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 panics if the position is not the beginning of a label or is beyond the end of the name.
sourcepub fn truncate(&mut self, len: usize)where
Octs: Truncate,
pub fn truncate(&mut self, len: usize)where Octs: Truncate,
Truncates the name to the given length.
Panics
The method panics if the position is not the beginning of a label or is beyond the end of the name.
sourcepub fn split_first(&self) -> Option<(&Label, RelativeDname<Octs::Range<'_>>)>where
Octs: Octets,
pub fn split_first(&self) -> Option<(&Label, RelativeDname<Octs::Range<'_>>)>where Octs: Octets,
Splits off the first label.
If there is at least one label in the name, returns the first label
as a relative domain name with exactly one label and makes self
contain the domain name starting after that first label. If the name
is empty, returns None
.
sourcepub fn parent(&self) -> Option<RelativeDname<Octs::Range<'_>>>where
Octs: Octets,
pub fn parent(&self) -> Option<RelativeDname<Octs::Range<'_>>>where Octs: Octets,
Returns the parent name.
Returns None
if the name was empty.
sourcepub fn strip_suffix<N: ToRelativeDname>(
&mut self,
base: &N
) -> Result<(), StripSuffixError>where
Octs: Truncate,
pub fn strip_suffix<N: ToRelativeDname>( &mut self, base: &N ) -> Result<(), StripSuffixError>where Octs: Truncate,
Strips the suffix base
from the domain name.
This will fail if base
isn’t actually a suffix, i.e., if
ends_with
doesn’t return true
.
Trait Implementations§
source§impl<Octs> AsRef<Octs> for RelativeDname<Octs>
impl<Octs> AsRef<Octs> for RelativeDname<Octs>
source§impl<Octs: Clone + ?Sized> Clone for RelativeDname<Octs>
impl<Octs: Clone + ?Sized> Clone for RelativeDname<Octs>
source§fn clone(&self) -> RelativeDname<Octs>
fn clone(&self) -> RelativeDname<Octs>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Octets> From<RelativeDname<Octets>> for UncertainDname<Octets>
impl<Octets> From<RelativeDname<Octets>> for UncertainDname<Octets>
source§fn from(src: RelativeDname<Octets>) -> Self
fn from(src: RelativeDname<Octets>) -> Self
source§impl<Octs> FromStr for RelativeDname<Octs>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder + FreezeBuilder<Octets = Octs> + AsRef<[u8]> + AsMut<[u8]>,
impl<Octs> FromStr for RelativeDname<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.
This implementation will error if the name ends in a dot since that indicates an absolute name.
§type Err = RelativeFromStrError
type Err = RelativeFromStrError
source§impl<'a, Octs> IntoIterator for &'a RelativeDname<Octs>where
Octs: AsRef<[u8]> + ?Sized,
impl<'a, Octs> IntoIterator for &'a RelativeDname<Octs>where Octs: AsRef<[u8]> + ?Sized,
source§impl<Octs, SrcOcts> OctetsFrom<RelativeDname<SrcOcts>> for RelativeDname<Octs>where
Octs: OctetsFrom<SrcOcts>,
impl<Octs, SrcOcts> OctetsFrom<RelativeDname<SrcOcts>> for RelativeDname<Octs>where Octs: OctetsFrom<SrcOcts>,
type Error = <Octs as OctetsFrom<SrcOcts>>::Error
source§fn try_octets_from(source: RelativeDname<SrcOcts>) -> Result<Self, Self::Error>
fn try_octets_from(source: RelativeDname<SrcOcts>) -> Result<Self, Self::Error>
source§impl<Octs, N> PartialEq<N> for RelativeDname<Octs>where
Octs: AsRef<[u8]> + ?Sized,
N: ToRelativeDname + ?Sized,
impl<Octs, N> PartialEq<N> for RelativeDname<Octs>where Octs: AsRef<[u8]> + ?Sized, N: ToRelativeDname + ?Sized,
source§impl<Octs, N> PartialOrd<N> for RelativeDname<Octs>where
Octs: AsRef<[u8]> + ?Sized,
N: ToRelativeDname + ?Sized,
impl<Octs, N> PartialOrd<N> for RelativeDname<Octs>where Octs: AsRef<[u8]> + ?Sized, N: ToRelativeDname + ?Sized,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<Octs> ToLabelIter for RelativeDname<Octs>where
Octs: AsRef<[u8]> + ?Sized,
impl<Octs> ToLabelIter for RelativeDname<Octs>where Octs: AsRef<[u8]> + ?Sized,
§type LabelIter<'a> = DnameIter<'a>
where
Octs: 'a
type LabelIter<'a> = DnameIter<'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
.