Struct domain::base::name::Label

source ·
pub struct Label(_);
Expand description

An octets slice with the content of a domain name label.

This is an unsized type wrapping the content of a valid label.

There are two types of such labels: normal labels and binary labels. Normal labels consist of up to 63 octets of data. Binary labels are a sequence of up to 256 one-bit labels. They have been invented for reverse pointer records for IPv6 but have quickly been found to be rather unwieldy and were never widely implemented. Subsequently they have been declared historic and are forbidden to be supported. So we don’t.

In theory there can be even more types of labels, but based on the experience with binary labels, it is very unlikely that there ever will be any.

Consequently, Label will only ever contain an octets slice of up to 63 octets. It only contains the label’s content, not the length octet it is preceded by in wire format. As an unsized type, it needs to be used behind some kind of pointer, most likely a reference.

Label differs from an octets slice in how it compares: as labels are to be case-insensitive, all the comparison traits as well as Hash are implemented ignoring ASCII-case.

Implementations§

source§

impl Label

source

pub const MAX_LEN: usize = 63usize

Domain name labels have a maximum length of 63 octets.

source

pub fn root() -> &'static Self

Returns a static reference to the root label.

The root label is an empty label.

source

pub fn wildcard() -> &'static Self

Returns a static reference to the wildcard label "*".

source

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

Converts an octets slice into a label.

This will fail if the slice is longer than 63 octets.

source

pub fn from_slice_mut(slice: &mut [u8]) -> Result<&mut Self, LongLabelError>

Converts a mutable octets slice into a label.

This will fail of the slice is longer than 63 octets.

source

pub fn split_from(slice: &[u8]) -> Result<(&Self, &[u8]), SplitLabelError>

Splits a label from the beginning of an octets slice.

On success, the function returns a label and the remainder of the slice.

source

pub fn split_from_mut( slice: &mut [u8] ) -> Result<(&mut Self, &mut [u8]), SplitLabelError>

Splits a mutable label from the beginning of an octets slice.

On success, the function returns a label and the remainder of the slice.

source

pub fn iter(&self) -> Copied<Iter<'_, u8>>

Iterator over the octets of the label.

source

pub fn iter_slice(slice: &[u8], start: usize) -> SliceLabelsIter<'_>

Iterates over the labels in some part of an octets slice.

The first label is assumed to start at index start.

Stops at the root label, the first broken label, or if a compression pointer is found that is pointing forward.

Panics

Panics if start is beyond the end of slice.

source

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

Returns a reference to the underlying octets slice.

source

pub fn as_slice_mut(&mut self) -> &mut [u8]

Returns a mutable reference to the underlying octets slice.

source

pub fn make_canonical(&mut self)

Converts the label into the canonical form.

This form has all octets representing ASCII letters converted to their lower case form.

source

pub fn to_canonical(&self) -> OwnedLabel

Returns the label in canonical form.

In this form, all ASCII letters are lowercase.

source

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

Returns the composed label ordering.

source

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

Returns the composed ordering with ASCII letters lowercased.

source

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

Appends the label to an octets builder.

The method builds the encoded form of the label that starts with a one octet length indicator.

source

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

Appends the lowercased label to an octets builder.

The method builds the encoded form of the label that starts with a one octet length indicator. It also converts all ASCII letters into their lowercase form.

source§

impl Label

source

pub fn len(&self) -> usize

Returns the length of the label.

This length is that of the label’s content only. It will not contain the initial label length octet present in the wire format.

source

pub fn is_empty(&self) -> bool

Returns whether this is the empty label.

source

pub fn is_root(&self) -> bool

Returns whether the label is the root label.

source

pub fn is_wildcard(&self) -> bool

Returns whether the label is the wildcard label.

source

pub fn compose_len(&self) -> u16

Returns the length of the composed version of the label.

This length is one more than the length of the label as their is a leading length octet.

Trait Implementations§

source§

impl AsMut<[u8]> for Label

source§

fn as_mut(&mut self) -> &mut [u8]

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

impl AsMut<Label> for OwnedLabel

source§

fn as_mut(&mut self) -> &mut Label

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

impl AsRef<[u8]> for Label

source§

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

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

impl AsRef<Label> for OwnedLabel

source§

fn as_ref(&self) -> &Label

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

impl Borrow<Label> for OwnedLabel

source§

fn borrow(&self) -> &Label

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<Label> for OwnedLabel

source§

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

Mutably borrows from an owned value. Read more
source§

impl Debug for Label

source§

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

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

impl Display for Label

source§

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

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

impl<'a> From<&'a Label> for OwnedLabel

source§

fn from(label: &'a Label) -> Self

Converts to this type from the input type.
source§

impl Hash for Label

source§

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

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

impl<'a> IntoIterator for &'a Label

§

type Item = u8

The type of the elements being iterated over.
§

type IntoIter = Copied<Iter<'a, u8>>

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 Ord for Label

source§

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

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

impl<T: AsRef<[u8]> + ?Sized> PartialEq<T> for Label

source§

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

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

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

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

impl PartialOrd<Label> for Label

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Returns an ordering between self and other.

The canonical sort order for labels is defined in section 6.1 of RFC 4034.

In short, labels are ordered like octet strings except that the case of ASCII letters is ignored.

1.0.0 · source§

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

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

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

This method 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

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

impl ToOwned for Label

§

type Owned = OwnedLabel

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

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

fn clone_into(&self, target: &mut Self::Owned)

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

impl Eq for Label

Auto Trait Implementations§

§

impl RefUnwindSafe for Label

§

impl Send for Label

§

impl !Sized for Label

§

impl Sync for Label

§

impl Unpin for Label

§

impl UnwindSafe for Label

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more