Struct domain::base::name::RelativeDname

source ·
pub struct RelativeDname<Octs: ?Sized>(/* private fields */);
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>

§Creating Values

source

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.

source

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.

source

pub fn empty() -> Self
where Octs: From<&'static [u8]>,

Creates an empty relative domain name.

source

pub fn wildcard() -> Self
where 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.

source

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]>

source

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");
source

pub fn empty_slice() -> &'static Self

Returns an empty relative name atop a unsized slice.

source

pub fn wildcard_slice() -> &'static Self

source§

impl RelativeDname<&'static [u8]>

source

pub fn empty_ref() -> Self

Creates an empty relative name atop a slice reference.

source

pub fn wildcard_ref() -> Self

Creates a wildcard relative name atop a slice reference.

source§

impl RelativeDname<Vec<u8>>

source

pub fn empty_vec() -> Self

Creates an empty relative name atop a Vec<u8>.

source

pub fn wildcard_vec() -> Self

Creates a wildcard relative name atop a Vec<u8>.

source

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>

source

pub fn empty_bytes() -> Self

Creates an empty relative name atop a bytes value.

source

pub fn wildcard_bytes() -> Self

Creates a wildcard relative name atop a bytes value.

source

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>

§Conversions

source

pub fn as_octets(&self) -> &Octs

Returns a reference to the underlying octets.

source

pub fn into_octets(self) -> Octs
where Octs: Sized,

Converts the name into the underlying octets.

source

pub fn for_ref(&self) -> RelativeDname<&Octs>

Returns a domain name using a reference to the octets.

source

pub fn as_slice(&self) -> &[u8]
where Octs: AsRef<[u8]>,

Returns a reference to an octets slice with the content of the name.

source

pub fn for_slice(&self) -> &RelativeDname<[u8]>
where Octs: AsRef<[u8]>,

Returns a domain name for the octets slice of the content.

source

pub fn make_canonical(&mut self)
where Octs: AsMut<[u8]>,

Converts the name into its canonical form.

source§

impl<Octs> RelativeDname<Octs>

source

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.

source

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>.

source

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

pub fn chain_root(self) -> Chain<Self, Dname<&'static [u8]>>
where Octs: AsRef<[u8]>,

Creates an absolute name by chaining the root label to it.

source§

impl<Octs: AsRef<[u8]> + ?Sized> RelativeDname<Octs>

§Properties

source

pub fn len(&self) -> usize

Returns the length of the name.

source

pub fn is_empty(&self) -> bool

Returns whether the name is empty.

source§

impl<Octs: AsRef<[u8]> + ?Sized> RelativeDname<Octs>

§Working with Labels

source

pub fn iter(&self) -> DnameIter<'_>

Returns an iterator over the labels of the domain name.

source

pub fn label_count(&self) -> usize

Returns the number of labels in the name.

source

pub fn first(&self) -> Option<&Label>

Returns a reference to the first label if the name isn’t empty.

source

pub fn last(&self) -> Option<&Label>

Returns a reference to the last label if the name isn’t empty.

source

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.

source

pub fn starts_with<N: ToLabelIter>(&self, base: &N) -> bool

Determines whether base is a prefix of self.

source

pub fn ends_with<N: ToLabelIter>(&self, base: &N) -> bool

Determines whether base is a suffix of self.

source

pub fn is_label_start(&self, index: usize) -> bool

Returns whether an index points to the first octet of a label.

source

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.

source

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>

source

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.

source

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.

source

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.

source

pub fn parent(&self) -> Option<RelativeDname<Octs::Range<'_>>>
where Octs: Octets,

Returns the parent name.

Returns None if the name was empty.

source

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<[u8]> + ?Sized> AsRef<[u8]> for RelativeDname<Octs>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<Octs> AsRef<Octs> for RelativeDname<Octs>

source§

fn as_ref(&self) -> &Octs

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<Octs: Clone + ?Sized> Clone for RelativeDname<Octs>

source§

fn clone(&self) -> RelativeDname<Octs>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Octs: AsRef<[u8]> + ?Sized> Debug for RelativeDname<Octs>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Octs: AsRef<[u8]> + ?Sized> Display for RelativeDname<Octs>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Octets> From<RelativeDname<Octets>> for UncertainDname<Octets>

source§

fn from(src: RelativeDname<Octets>) -> Self

Converts to this type from the input type.
source§

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>

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

The associated error which can be returned from parsing.
source§

impl<Octs: AsRef<[u8]> + ?Sized> Hash for RelativeDname<Octs>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
source§

impl<'a, Octs> IntoIterator for &'a RelativeDname<Octs>
where Octs: AsRef<[u8]> + ?Sized,

§

type Item = &'a Label

The type of the elements being iterated over.
§

type IntoIter = DnameIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

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>

Performs the conversion.
source§

impl<Octs: AsRef<[u8]> + ?Sized> Ord for RelativeDname<Octs>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl<Octs, N> PartialEq<N> for RelativeDname<Octs>
where Octs: AsRef<[u8]> + ?Sized, N: ToRelativeDname + ?Sized,

source§

fn eq(&self, other: &N) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Octs, N> PartialOrd<N> for RelativeDname<Octs>
where Octs: AsRef<[u8]> + ?Sized, N: ToRelativeDname + ?Sized,

source§

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 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<Octs> ToLabelIter for RelativeDname<Octs>
where Octs: AsRef<[u8]> + ?Sized,

§

type LabelIter<'a> = DnameIter<'a> where Octs: 'a

The type of the iterator over the labels. Read more
source§

fn iter_labels(&self) -> Self::LabelIter<'_>

Returns an iterator over the labels.
source§

fn compose_len(&self) -> u16

Returns the length in octets of the encoded name.
source§

fn starts_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool

Determines whether base is a prefix of self.
source§

fn ends_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool

Determines whether base is a suffix of self.
source§

impl<Octs: AsRef<[u8]> + ?Sized> ToRelativeDname for RelativeDname<Octs>

source§

fn as_flat_slice(&self) -> Option<&[u8]>

Returns a byte slice of the content if possible. Read more
source§

fn is_empty(&self) -> bool

Returns whether the name is empty.
source§

fn to_relative_dname<Octets>( &self, ) -> Result<RelativeDname<Octets>, BuilderAppendError<Octets>>
where Octets: FromBuilder, <Octets as FromBuilder>::Builder: EmptyBuilder,

Converts the name into a single, continous name. Read more
source§

fn to_canonical_relative_dname<Octets>( &self, ) -> Result<RelativeDname<Octets>, BuilderAppendError<Octets>>
where Octets: FromBuilder, <Octets as FromBuilder>::Builder: EmptyBuilder,

Converts the name into a single name in canonical form.
source§

fn compose<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

source§

fn compose_canonical<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

source§

fn to_cow(&self) -> RelativeDname<Cow<'_, [u8]>>

Returns a cow of the relative domain name. Read more
source§

fn to_vec(&self) -> RelativeDname<Vec<u8>>

Returns the domain name assembled into a Vec<u8>.
source§

fn to_bytes(&self) -> RelativeDname<Bytes>

Returns the domain name assembled into a bytes value.
source§

fn name_eq<N: ToRelativeDname + ?Sized>(&self, other: &N) -> bool

Tests whether self and other are equal. Read more
source§

fn name_cmp<N: ToRelativeDname + ?Sized>(&self, other: &N) -> Ordering

Returns the ordering between self and other. Read more
source§

impl<Octs: AsRef<[u8]> + ?Sized> Eq for RelativeDname<Octs>

Auto Trait Implementations§

§

impl<Octs> Freeze for RelativeDname<Octs>
where Octs: Freeze + ?Sized,

§

impl<Octs> RefUnwindSafe for RelativeDname<Octs>
where Octs: RefUnwindSafe + ?Sized,

§

impl<Octs> Send for RelativeDname<Octs>
where Octs: Send + ?Sized,

§

impl<Octs> Sync for RelativeDname<Octs>
where Octs: Sync + ?Sized,

§

impl<Octs> Unpin for RelativeDname<Octs>
where Octs: Unpin + ?Sized,

§

impl<Octs> UnwindSafe for RelativeDname<Octs>
where Octs: UnwindSafe + ?Sized,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

§

type Error = <Target as OctetsFrom<Source>>::Error

source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more