[][src]Struct domain_core::bits::name::RelativeDname

pub struct RelativeDname { /* fields omitted */ }

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 Bytes value 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).

Methods

impl RelativeDname[src]

pub fn empty() -> Self[src]

Creates an empty relative domain name.

Determining what this could possibly be useful for is left as an excercise to the reader.

pub fn wildcard() -> Self[src]

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.

pub fn from_bytes(bytes: Bytes) -> Result<Self, RelativeDnameError>[src]

Creates a relative domain name from a bytes value.

This checks that bytes contains a properly encoded relative domain name and fails if it doesn’t.

pub fn from_slice(slice: &[u8]) -> Result<Self, RelativeDnameError>[src]

Creates a relative domain name from a byte slice.

The function will create a new bytes value from the slice’s content. If the slice does not contain a correctly encoded, relative domain name, the function will fail.

pub fn as_bytes(&self) -> &Bytes[src]

Returns a reference to the underlying bytes value.

pub fn as_slice(&self) -> &[u8][src]

Returns a reference to the underlying byte slice.

pub fn into_bytes(self) -> Bytes[src]

Converts the name into the underlying bytes value.

pub fn into_builder(self) -> DnameBuilder[src]

Converts the name into a domain name builder for appending data.

If the underlying bytes value can be converted into a BytesMut (via its try_mut method), the builder will use that directly. Otherwise, it will create an all new BytesMut from the name’s content.

pub fn into_absolute(self) -> Dname[src]

Converts the name into an absolute name by appending the root label.

This manipulates the name itself and thus may have to copy it. If you just need an absolute name, you can perhaps use chain_root instead.

pub fn chain<N: Compose>(
    self,
    other: N
) -> Result<Chain<Self, N>, LongChainError>
[src]

Creates a domain name by concatenating self with other.

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.

pub fn chain_root(self) -> Chain<Self, Dname>[src]

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

impl RelativeDname[src]

Important traits for DnameIter<'a>
pub fn iter(&self) -> DnameIter[src]

Returns an iterator over the labels of the domain name.

pub fn label_count(&self) -> usize[src]

Returns the number of labels in the name.

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

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

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

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

pub fn ndots(&self) -> usize[src]

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.

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 is_label_start(&self, index: usize) -> bool[src]

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

pub fn slice(&self, begin: usize, end: usize) -> Self[src]

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 need to be the beginning of a label.

Panics

The method panics if either position is not the beginning of a label or is out of bounds.

pub fn slice_from(&self, begin: usize) -> Self[src]

Returns the part of the name starting at the given position.

Panics

The method panics if the position is not the beginning of a label or is beyond the end of the name.

pub fn slice_to(&self, end: usize) -> Self[src]

Returns the part of the name ending before the given position.

Panics

The method panics if the position is not the beginning of a label or is beyond the end of the name.

pub fn split_off(&mut self, mid: usize) -> Self[src]

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.

pub fn split_to(&mut self, mid: usize) -> Self[src]

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.

pub fn truncate(&mut self, len: usize)[src]

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.

pub fn split_first(&mut self) -> Option<Self>[src]

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.

pub fn parent(&mut self) -> bool[src]

Reduces the name to its parent.

Returns whether that actually happened, since if the name is already empty it can’t.

pub fn strip_suffix<N: ToRelativeDname>(
    &mut self,
    base: &N
) -> Result<(), StripSuffixError>
[src]

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.

Methods from Deref<Target = Bytes>

pub fn len(&self) -> usize[src]

Returns the number of bytes contained in this Bytes.

Examples

use bytes::Bytes;

let b = Bytes::from(&b"hello"[..]);
assert_eq!(b.len(), 5);

pub fn is_empty(&self) -> bool[src]

Returns true if the Bytes has a length of 0.

Examples

use bytes::Bytes;

let b = Bytes::new();
assert!(b.is_empty());

pub fn slice(&self, begin: usize, end: usize) -> Bytes[src]

Returns a slice of self for the index range [begin..end).

This will increment the reference count for the underlying memory and return a new Bytes handle set to the slice.

This operation is O(1).

Examples

use bytes::Bytes;

let a = Bytes::from(&b"hello world"[..]);
let b = a.slice(2, 5);

assert_eq!(&b[..], b"llo");

Panics

Requires that begin <= end and end <= self.len(), otherwise slicing will panic.

pub fn slice_from(&self, begin: usize) -> Bytes[src]

Returns a slice of self for the index range [begin..self.len()).

This will increment the reference count for the underlying memory and return a new Bytes handle set to the slice.

This operation is O(1) and is equivalent to self.slice(begin, self.len()).

Examples

use bytes::Bytes;

let a = Bytes::from(&b"hello world"[..]);
let b = a.slice_from(6);

assert_eq!(&b[..], b"world");

Panics

Requires that begin <= self.len(), otherwise slicing will panic.

pub fn slice_to(&self, end: usize) -> Bytes[src]

Returns a slice of self for the index range [0..end).

This will increment the reference count for the underlying memory and return a new Bytes handle set to the slice.

This operation is O(1) and is equivalent to self.slice(0, end).

Examples

use bytes::Bytes;

let a = Bytes::from(&b"hello world"[..]);
let b = a.slice_to(5);

assert_eq!(&b[..], b"hello");

Panics

Requires that end <= self.len(), otherwise slicing will panic.

pub fn slice_ref(&self, subset: &[u8]) -> Bytes[src]

Returns a slice of self that is equivalent to the given subset.

When processing a Bytes buffer with other tools, one often gets a &[u8] which is in fact a slice of the Bytes, i.e. a subset of it. This function turns that &[u8] into another Bytes, as if one had called self.slice() with the offsets that correspond to subset.

This operation is O(1).

Examples

use bytes::Bytes;

let bytes = Bytes::from(&b"012345678"[..]);
let as_slice = bytes.as_ref();
let subset = &as_slice[2..6];
let subslice = bytes.slice_ref(&subset);
assert_eq!(&subslice[..], b"2345");

Panics

Requires that the given sub slice is in fact contained within the Bytes buffer; otherwise this function will panic.

Trait Implementations

impl Compose for RelativeDname[src]

impl<'a> ToLabelIter<'a> for RelativeDname[src]

type LabelIter = DnameIter<'a>

The type of the iterator over the labels. Read more

fn starts_with<N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool[src]

Determines whether base is a prefix of self.

fn ends_with<N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool[src]

Determines whether base is a suffix of self.

impl ToRelativeDname for RelativeDname[src]

fn chain<N: Compose>(self, suffix: N) -> Result<Chain<Self, N>, LongChainError> where
    Self: Sized
[src]

Returns a chain of this name and the provided absolute name.

fn chain_root(self) -> Chain<Self, Dname> where
    Self: Sized
[src]

Returns the absolute name by chaining it with the root label.

fn name_eq<N: ToRelativeDname>(&self, other: &N) -> bool[src]

Tests whether self and other are equal. Read more

fn name_cmp<N: ToRelativeDname>(&self, other: &N) -> Ordering[src]

Returns the ordering between self and other. Read more

impl<'a> IntoIterator for &'a RelativeDname[src]

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?

impl Eq for RelativeDname[src]

impl Clone for RelativeDname[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialOrd<RelativeDname> for RelativeDname[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<N: ToRelativeDname> PartialEq<N> for RelativeDname[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl AsRef<Bytes> for RelativeDname[src]

impl AsRef<[u8]> for RelativeDname[src]

impl Ord for RelativeDname[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl From<RelativeDname> for UncertainDname[src]

impl Deref for RelativeDname[src]

type Target = Bytes

The resulting type after dereferencing.

impl Hash for RelativeDname[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for RelativeDname[src]

impl Display for RelativeDname[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]