Struct domain::base::RelativeDname
source · [−]pub struct RelativeDname<Octets: ?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
sourceimpl<Octets> RelativeDname<Octets>
impl<Octets> RelativeDname<Octets>
sourcepub const unsafe fn from_octets_unchecked(octets: Octets) -> Self
pub const unsafe fn from_octets_unchecked(octets: Octets) -> 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: Octets) -> Result<Self, RelativeDnameError>where
Octets: AsRef<[u8]>,
pub fn from_octets(octets: Octets) -> Result<Self, RelativeDnameError>where
Octets: 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 empty() -> Selfwhere
Octets: From<&'static [u8]>,
pub fn empty() -> Selfwhere
Octets: From<&'static [u8]>,
Creates an empty relative domain name.
sourcepub fn wildcard() -> Selfwhere
Octets: From<&'static [u8]>,
pub fn wildcard() -> Selfwhere
Octets: 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.
sourceimpl 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.
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
sourceimpl 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.
sourceimpl 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>
.
sourceimpl 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.
sourceimpl<Octets: ?Sized> RelativeDname<Octets>
impl<Octets: ?Sized> RelativeDname<Octets>
sourcepub fn into_octets(self) -> Octetswhere
Octets: Sized,
pub fn into_octets(self) -> Octetswhere
Octets: Sized,
Converts the name into the underlying octets.
sourcepub fn for_ref(&self) -> RelativeDname<&Octets>
pub fn for_ref(&self) -> RelativeDname<&Octets>
Returns a domain name using a reference to the octets.
sourceimpl<Octets> RelativeDname<Octets>
impl<Octets> RelativeDname<Octets>
sourcepub fn into_builder(self) -> DnameBuilder<<Octets as IntoBuilder>::Builder>where
Octets: IntoBuilder,
pub fn into_builder(self) -> DnameBuilder<<Octets as IntoBuilder>::Builder>where
Octets: 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<<<Octets as IntoBuilder>::Builder as OctetsBuilder>::Octets>, PushError>where
Octets: IntoBuilder,
<Octets as IntoBuilder>::Builder: AsMut<[u8]>,
pub fn into_absolute(
self
) -> Result<Dname<<<Octets as IntoBuilder>::Builder as OctetsBuilder>::Octets>, PushError>where
Octets: IntoBuilder,
<Octets as IntoBuilder>::Builder: 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 builer and back
such as Vec<u8>
.
sourcepub fn chain<N: ToEitherDname>(
self,
other: N
) -> Result<Chain<Self, N>, LongChainError>where
Octets: AsRef<[u8]>,
pub fn chain<N: ToEitherDname>(
self,
other: N
) -> Result<Chain<Self, N>, LongChainError>where
Octets: 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.
sourceimpl<Octets: AsRef<[u8]> + ?Sized> RelativeDname<Octets>
impl<Octets: AsRef<[u8]> + ?Sized> RelativeDname<Octets>
sourcepub fn iter(&self) -> DnameIter<'_>ⓘNotable traits for DnameIter<'a>impl<'a> Iterator for DnameIter<'a> type Item = &'a Label;
pub fn iter(&self) -> DnameIter<'_>ⓘNotable traits for DnameIter<'a>impl<'a> Iterator for DnameIter<'a> type Item = &'a Label;
Returns an iterator over the labels of the domain name.
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<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
pub fn starts_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
Determines whether base
is a prefix of self
.
sourcepub fn ends_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
pub fn ends_with<'a, N: ToLabelIter<'a>>(&'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 octet of a label.
sourcepub fn slice(&self, begin: usize, end: usize) -> &RelativeDname<[u8]>
pub fn slice(&self, begin: usize, end: 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 slice_from(&self, begin: usize) -> &RelativeDname<[u8]>
pub fn slice_from(&self, begin: usize) -> &RelativeDname<[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 the position is not the beginning of a label or is beyond the end of the name.
sourcepub fn slice_to(&self, end: usize) -> &RelativeDname<[u8]>
pub fn slice_to(&self, end: usize) -> &RelativeDname<[u8]>
Returns the part of the name ending before the given position.
The returned name will start at beginning of the name and continue
until just before the given postion. The position end
is considered
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_to
is likely a better choice.
Panics
The method panics if the position is not the beginning of a label or is beyond the end of the name.
sourcepub fn range<'a>(
&'a self,
begin: usize,
end: usize
) -> RelativeDname<<&'a Octets as OctetsRef>::Range>where
&'a Octets: OctetsRef,
pub fn range<'a>(
&'a self,
begin: usize,
end: usize
) -> RelativeDname<<&'a Octets as OctetsRef>::Range>where
&'a Octets: OctetsRef,
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.
sourcepub fn range_from<'a>(
&'a self,
begin: usize
) -> RelativeDname<<&'a Octets as OctetsRef>::Range>where
&'a Octets: OctetsRef,
pub fn range_from<'a>(
&'a self,
begin: usize
) -> RelativeDname<<&'a Octets as OctetsRef>::Range>where
&'a Octets: OctetsRef,
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 the position is not the beginning of a label or is beyond the end of the name.
sourcepub fn range_to<'a>(
&'a self,
end: usize
) -> RelativeDname<<&'a Octets as OctetsRef>::Range>where
&'a Octets: OctetsRef,
pub fn range_to<'a>(
&'a self,
end: usize
) -> RelativeDname<<&'a Octets as OctetsRef>::Range>where
&'a Octets: OctetsRef,
Returns the part of the name ending before the given position.
The returned name will start at beginning of the name and continue
until just before the given postion. The position end
is considered
as an index into the underlying octets sequence and must point to the
beginning of a label.
Panics
The method panics if the position is not the beginning of a label or is beyond the end of the name.
sourceimpl<Octets: AsRef<[u8]>> RelativeDname<Octets>
impl<Octets: AsRef<[u8]>> RelativeDname<Octets>
sourcepub fn split_off(&mut self, mid: usize) -> Selfwhere
for<'a> &'a Octets: OctetsRef<Range = Octets>,
pub fn split_off(&mut self, mid: usize) -> Selfwhere
for<'a> &'a Octets: OctetsRef<Range = Octets>,
Splits the name into two at the given position.
Afterwards, self
will contain the name ending before the position
while the name starting at the position will be returned.
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_to(&mut self, mid: usize) -> Selfwhere
for<'a> &'a Octets: OctetsRef<Range = Octets>,
pub fn split_to(&mut self, mid: usize) -> Selfwhere
for<'a> &'a Octets: OctetsRef<Range = Octets>,
Splits the name into two at the given position.
Afterwards, self
will contain the name starting at the position
while the name ending right before it will be returned.
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
Octets: OctetsExt,
pub fn truncate(&mut self, len: usize)where
Octets: OctetsExt,
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(&mut self) -> Option<Self>where
for<'a> &'a Octets: OctetsRef<Range = Octets>,
pub fn split_first(&mut self) -> Option<Self>where
for<'a> &'a Octets: OctetsRef<Range = 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(&mut self) -> boolwhere
for<'a> &'a Octets: OctetsRef<Range = Octets>,
pub fn parent(&mut self) -> boolwhere
for<'a> &'a Octets: OctetsRef<Range = Octets>,
Reduces the name to its parent.
Returns whether that actually happened, since an empty name doesn’t have a parent.
sourcepub fn strip_suffix<N: ToRelativeDname>(
&mut self,
base: &N
) -> Result<(), StripSuffixError>where
for<'a> &'a Octets: OctetsRef<Range = Octets>,
pub fn strip_suffix<N: ToRelativeDname>(
&mut self,
base: &N
) -> Result<(), StripSuffixError>where
for<'a> &'a Octets: OctetsRef<Range = Octets>,
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
sourceimpl<Octets: Clone + ?Sized> Clone for RelativeDname<Octets>
impl<Octets: Clone + ?Sized> Clone for RelativeDname<Octets>
sourcefn clone(&self) -> RelativeDname<Octets>
fn clone(&self) -> RelativeDname<Octets>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<Octets: AsRef<[u8]> + ?Sized> Compose for RelativeDname<Octets>
impl<Octets: AsRef<[u8]> + ?Sized> Compose for RelativeDname<Octets>
sourcefn compose<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
fn compose<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
Appends the concrete representation of the value to the target. Read more
sourcefn compose_canonical<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
fn compose_canonical<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
Appends the canonical representation of the value to the target. Read more
sourceimpl<Octets: ?Sized> Deref for RelativeDname<Octets>
impl<Octets: ?Sized> Deref for RelativeDname<Octets>
sourceimpl<'de, Octets> Deserialize<'de> for RelativeDname<Octets>where
Octets: FromBuilder + DeserializeOctets<'de>,
<Octets as FromBuilder>::Builder: EmptyBuilder + AsMut<[u8]>,
impl<'de, Octets> Deserialize<'de> for RelativeDname<Octets>where
Octets: FromBuilder + DeserializeOctets<'de>,
<Octets as FromBuilder>::Builder: EmptyBuilder + AsMut<[u8]>,
sourcefn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<Octets> From<RelativeDname<Octets>> for UncertainDname<Octets>
impl<Octets> From<RelativeDname<Octets>> for UncertainDname<Octets>
sourcefn from(src: RelativeDname<Octets>) -> Self
fn from(src: RelativeDname<Octets>) -> Self
Converts to this type from the input type.
sourceimpl<'a, Octets> IntoIterator for &'a RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
impl<'a, Octets> IntoIterator for &'a RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
sourceimpl<Octets, SrcOctets> OctetsFrom<RelativeDname<SrcOctets>> for RelativeDname<Octets>where
Octets: OctetsFrom<SrcOctets>,
impl<Octets, SrcOctets> OctetsFrom<RelativeDname<SrcOctets>> for RelativeDname<Octets>where
Octets: OctetsFrom<SrcOctets>,
sourcefn octets_from(source: RelativeDname<SrcOctets>) -> Result<Self, ShortBuf>
fn octets_from(source: RelativeDname<SrcOctets>) -> Result<Self, ShortBuf>
Performs the conversion.
sourceimpl<Octets, N> PartialEq<N> for RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
N: ToRelativeDname + ?Sized,
impl<Octets, N> PartialEq<N> for RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
N: ToRelativeDname + ?Sized,
sourceimpl<Octets, N> PartialOrd<N> for RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
N: ToRelativeDname + ?Sized,
impl<Octets, N> PartialOrd<N> for RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
N: ToRelativeDname + ?Sized,
sourcefn partial_cmp(&self, other: &N) -> Option<Ordering>
fn partial_cmp(&self, other: &N) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl<Octets> Serialize for RelativeDname<Octets>where
Octets: AsRef<[u8]> + SerializeOctets,
impl<Octets> Serialize for RelativeDname<Octets>where
Octets: AsRef<[u8]> + SerializeOctets,
sourceimpl<'a, Octets> ToLabelIter<'a> for RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
impl<'a, Octets> ToLabelIter<'a> for RelativeDname<Octets>where
Octets: AsRef<[u8]> + ?Sized,
sourcefn iter_labels(&'a self) -> Self::LabelIter
fn iter_labels(&'a self) -> Self::LabelIter
Returns an iterator over the labels.
sourcefn starts_with<N: ToLabelIter<'a> + ?Sized>(&'a self, base: &'a N) -> bool
fn starts_with<N: ToLabelIter<'a> + ?Sized>(&'a self, base: &'a N) -> bool
Determines whether base
is a prefix of self
.
sourceimpl<Octets: AsRef<[u8]> + ?Sized> ToRelativeDname for RelativeDname<Octets>
impl<Octets: AsRef<[u8]> + ?Sized> ToRelativeDname for RelativeDname<Octets>
sourcefn as_flat_slice(&self) -> Option<&[u8]>
fn as_flat_slice(&self) -> Option<&[u8]>
Returns a byte slice of the content if possible. Read more
sourcefn to_relative_dname<Octets>(&self) -> Result<RelativeDname<Octets>, PushError>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: EmptyBuilder,
fn to_relative_dname<Octets>(&self) -> Result<RelativeDname<Octets>, PushError>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: EmptyBuilder,
Converts the name into a single, continous name. Read more
sourcefn to_cow(&self) -> RelativeDname<Cow<'_, [u8]>>
fn to_cow(&self) -> RelativeDname<Cow<'_, [u8]>>
Returns a cow of the relative domain name. Read more
sourcefn to_vec(&self) -> RelativeDname<Vec<u8>>
fn to_vec(&self) -> RelativeDname<Vec<u8>>
Returns the domain name assembled into a Vec<u8>
.
sourcefn to_bytes(&self) -> RelativeDname<Bytes>
fn to_bytes(&self) -> RelativeDname<Bytes>
Returns the domain name assembled into a bytes value.
impl<Octets: AsRef<[u8]> + ?Sized> Eq for RelativeDname<Octets>
Auto Trait Implementations
impl<Octets: ?Sized> RefUnwindSafe for RelativeDname<Octets>where
Octets: RefUnwindSafe,
impl<Octets: ?Sized> Send for RelativeDname<Octets>where
Octets: Send,
impl<Octets: ?Sized> Sync for RelativeDname<Octets>where
Octets: Sync,
impl<Octets: ?Sized> Unpin for RelativeDname<Octets>where
Octets: Unpin,
impl<Octets: ?Sized> UnwindSafe for RelativeDname<Octets>where
Octets: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
sourcefn octets_into(self) -> Result<Target, ShortBuf>
fn octets_into(self) -> Result<Target, ShortBuf>
Performs the conversion.