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
impl Label
sourcepub fn root() -> &'static Self
pub fn root() -> &'static Self
Returns a static reference to the root label.
The root label is an empty label.
sourcepub fn wildcard() -> &'static Self
pub fn wildcard() -> &'static Self
Returns a static reference to the wildcard label "*"
.
sourcepub fn from_slice(slice: &[u8]) -> Result<&Self, LongLabelError>
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.
sourcepub fn from_slice_mut(slice: &mut [u8]) -> Result<&mut Self, LongLabelError>
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.
sourcepub fn split_from(slice: &[u8]) -> Result<(&Self, &[u8]), SplitLabelError>
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.
sourcepub fn split_from_mut(
slice: &mut [u8]
) -> Result<(&mut Self, &mut [u8]), SplitLabelError>
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.
sourcepub fn iter_slice(slice: &[u8], start: usize) -> SliceLabelsIter<'_> ⓘ
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
.
sourcepub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the underlying octets slice.
sourcepub fn make_canonical(&mut self)
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.
sourcepub fn to_canonical(&self) -> OwnedLabel
pub fn to_canonical(&self) -> OwnedLabel
Returns the label in canonical form.
In this form, all ASCII letters are lowercase.
sourcepub fn composed_cmp(&self, other: &Self) -> Ordering
pub fn composed_cmp(&self, other: &Self) -> Ordering
Returns the composed label ordering.
sourcepub fn lowercase_composed_cmp(&self, other: &Self) -> Ordering
pub fn lowercase_composed_cmp(&self, other: &Self) -> Ordering
Returns the composed ordering with ASCII letters lowercased.
sourcepub fn compose<Builder: OctetsBuilder + ?Sized>(
&self,
target: &mut Builder
) -> Result<(), Builder::AppendError>
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.
sourcepub fn compose_canonical<Builder: OctetsBuilder + ?Sized>(
&self,
target: &mut Builder
) -> Result<(), Builder::AppendError>
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
impl Label
sourcepub fn len(&self) -> usize
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.
sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Returns whether the label is the wildcard label.
sourcepub fn compose_len(&self) -> u16
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<Label> for OwnedLabel
impl AsMut<Label> for OwnedLabel
source§impl AsRef<Label> for OwnedLabel
impl AsRef<Label> for OwnedLabel
source§impl Borrow<Label> for OwnedLabel
impl Borrow<Label> for OwnedLabel
source§impl BorrowMut<Label> for OwnedLabel
impl BorrowMut<Label> for OwnedLabel
source§fn borrow_mut(&mut self) -> &mut Label
fn borrow_mut(&mut self) -> &mut Label
source§impl<'a> From<&'a Label> for OwnedLabel
impl<'a> From<&'a Label> for OwnedLabel
source§impl<'a> IntoIterator for &'a Label
impl<'a> IntoIterator for &'a Label
source§impl PartialOrd<Label> for Label
impl PartialOrd<Label> for Label
source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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 le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more