Struct domain::bits::DNameBuf
[−]
[src]
pub struct DNameBuf { /* fields omitted */ }
An owned complete domain name.
A value of this type contains a vector with a correctly encoded,
uncompressed domain name. It derefs to DNameSlice
in order to make
all its methods available for working with domain names.
In addition, it provides a number of methods to add labels or entire names to its end.
DNameBuf
values can be created from string via the std::str::FromStr
trait. Such strings must be in the usual zonefile encoding.
Methods
impl DNameBuf
[src]
fn new() -> Self
Creates a new empty domain name.
fn with_capacity(capacity: usize) -> DNameBuf
Creates a new empty name with the given amount of space reserved.
fn from_vec(vec: Vec<u8>) -> Option<Self>
Creates an owned domain name using an existing bytes vector.
If the content of the bytes vector does not constitute a correctly encoded uncompressed domain name, the function will fail.
fn try_from_iter<'a, T>(iter: T) -> Result<Self, PushError> where
T: IntoIterator<Item = &'a Label>,
T: IntoIterator<Item = &'a Label>,
Creates an owned domain name from the labels of the iterator.
fn scan<S: Scanner>(
scanner: &mut S,
origin: Option<&DNameSlice>
) -> ScanResult<Self>
scanner: &mut S,
origin: Option<&DNameSlice>
) -> ScanResult<Self>
Creates an owned domain name by reading it from a scanner.
fn root() -> DNameBuf
Returns a new owned domain name consisting only of the root label.
fn as_slice(&self) -> &DNameSlice
Returns a reference to a slice of the domain name.
fn into_vec(self) -> Vec<u8>
Extracts the underlying vector from the name.
impl DNameBuf
[src]
Manipulations
fn push(&mut self, label: &Label) -> Result<(), PushError>
Extends a relative name with a label.
If the name is absolute, nothing happens.
fn push_normal(&mut self, content: &[u8]) -> Result<(), PushError>
Pushes a normal label to the end of a relative name.
If the name is absolute, nothing happens. If the resulting name would exceed the maximum allowd length of 255 octets, returns an error.
Panics
The method panics if content
is longer that 63 bytes.
fn push_binary(&mut self, count: usize, bits: &[u8]) -> Result<(), PushError>
Pushes a binary label to the end of a relative name.
The binary label will be count
bits long and contain the bits
from bits
. If bits
is too short, the label will be filled up
with zero bits. If bits
is too long, it will be trimmed to the
right length.
If the name is absolute, nothing happens. If the resulting name would exceed the maximum allowd length of 255 octets, returns an error.
Panics
The method panics if count
is larger than 256.
fn push_empty_binary(
&mut self,
count: usize
) -> Result<Option<&mut [u8]>, PushError>
&mut self,
count: usize
) -> Result<Option<&mut [u8]>, PushError>
Pushes an empty binary label of the given length to the domain name.
Upon success the function returns a mutable reference to the bytes slice of the bits of the binary label.
If the name is already absolute, returns Ok(None)
. If the resulting
name would exceed the maximum allowd length of 255 octets, returns an
error.
Panics
The method panics if count
is larger than 256.
fn append<N: DName>(&mut self, name: &N) -> Result<(), PushError>
Extends a relative name with a domain name.
If the name is already absolute, nothing will be appended and the name remains unchanged. If by appending the name would exceed the maximum allowed length of 255 octets, an error will be returned and the name remains unchanged, too.
fn append_root(&mut self) -> Result<(), PushError>
Makes a domain name absolute if it isn’t yet by appending root.
This may fail if the name is already 255 octets long.
fn append_iter<'a, T>(&mut self, iter: T) -> Result<(), PushError> where
T: IntoIterator<Item = &'a Label>,
T: IntoIterator<Item = &'a Label>,
Appends the content of an iterator to the end of the name.
fn remove_first(&mut self)
Removes the first label.
After this operation, the content of self
is self.parent()
.
Panics
Panics if the name is empty.
Methods from Deref<Target = DNameSlice>
fn as_bytes(&self) -> &[u8]
Returns a reference to the underlying bytes slice.
fn to_owned(&self) -> DNameBuf
Converts the domain name slice to an owned domain name.
fn is_absolute(&self) -> bool
Checks whether the domain name is absolute.
A domain name is absolute if it ends with an empty normal label (the root label).
fn is_relative(&self) -> bool
Checks whether the domain name is relative, ie., not absolute.
fn labels(&self) -> NameLabels
Produces an iterator over the labels in the name.
fn labelettes(&self) -> NameLabelettes
Produces an iterator over the labelettes in the name.
fn len(&self) -> usize
Returns the number of labels in self
.
fn is_empty(&self) -> bool
Checks whether the domain name is empty.
fn first(&self) -> Option<&Label>
Returns the first label or None
if the name is empty.
fn last(&self) -> Option<&Label>
Returns the last label or None
if the name is empty.
fn ndots(&self) -> Option<usize>
Returns the number of dots if this is a relative name.
Returns None
if this is an absolute name.
fn split_first(&self) -> Option<(&Label, &Self)>
Returns the first label and the remaining domain name.
Returns None
only if the name is empty (which is different from a
name containing only the root label).
fn parent(&self) -> Option<&DNameSlice>
Returns the domain name without its leftmost label.
Returns None
for an empty domain name and a domain name consisting
of only the root label. Returns an empty domain name for a single
label relative domain name.
fn strip_suffix<'a, N: DName>(
&'a self,
base: &'a N
) -> Result<Cow<'a, Self>, StripSuffixError>
&'a self,
base: &'a N
) -> Result<Cow<'a, Self>, StripSuffixError>
Returns a domain name slice relative to base
.
This fails if base
isn’t a suffix of self
.
fn starts_with<N: DName>(&self, base: &N) -> bool
Determines whether base
is a prefix of self
.
fn ends_with<N: DName>(&self, base: &N) -> bool
Determines whether base
is a suffix of self
.
fn join<N: DName>(&self, base: &N) -> Result<DNameBuf, PushError>
Creates an owned domain name made absolute if necessary.
If self
is already an absolute domain name, nothing happens.
Trait Implementations
impl Clone for DNameBuf
[src]
fn clone(&self) -> DNameBuf
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Default for DNameBuf
[src]
impl DName for DNameBuf
[src]
fn to_cow(&self) -> Cow<DNameSlice>
Converts the name into an uncompressed name. Read more
fn labels(&self) -> NameLabels
Returns an iterator over the labels of the domain name.
fn labelettes(&self) -> NameLabelettes
Returns an iterator over the labelettes of the domain name. Read more
fn compose<C: AsMut<Composer>>(&self, composer: C) -> ComposeResult<()>
Appends the name to the end of a composition.
fn compose_compressed<C: AsMut<Composer>>(
&self,
composer: C
) -> ComposeResult<()>
&self,
composer: C
) -> ComposeResult<()>
Appends the name to the end of a composition using name compression.
impl<'a> DName for &'a DNameBuf
[src]
fn to_cow(&self) -> Cow<DNameSlice>
Converts the name into an uncompressed name. Read more
fn labels(&self) -> NameLabels
Returns an iterator over the labels of the domain name.
fn labelettes(&self) -> NameLabelettes
Returns an iterator over the labelettes of the domain name. Read more
fn compose<C: AsMut<Composer>>(&self, composer: C) -> ComposeResult<()>
Appends the name to the end of a composition.
fn compose_compressed<C: AsMut<Composer>>(
&self,
composer: C
) -> ComposeResult<()>
&self,
composer: C
) -> ComposeResult<()>
Appends the name to the end of a composition using name compression.
impl<'a> From<&'a DNameSlice> for DNameBuf
[src]
fn from(name: &'a DNameSlice) -> DNameBuf
Performs the conversion.
impl<'a> From<&'a Label> for DNameBuf
[src]
impl FromStr for DNameBuf
[src]
type Err = FromStrError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a new domain name from a string.
The string must follow zone file conventions. It must only contain
printable ASCII characters and no whitespace. Invidual labels are
separated by a dot. A backslash escapes the next character unless
that is a 0
, 1
, or 2
, in which case the next three characters
are the byte value in decimal representation.
impl Deref for DNameBuf
[src]
type Target = DNameSlice
The resulting type after dereferencing
fn deref(&self) -> &Self::Target
The method called to dereference a value
impl Borrow<DNameSlice> for DNameBuf
[src]
fn borrow(&self) -> &DNameSlice
Immutably borrows from an owned value. Read more
impl AsRef<DNameSlice> for DNameBuf
[src]
fn as_ref(&self) -> &DNameSlice
Performs the conversion.
impl<N: DName> PartialEq<N> for DNameBuf
[src]
fn eq(&self, other: &N) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialEq<str> for DNameBuf
[src]
fn eq(&self, other: &str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl Eq for DNameBuf
[src]
impl<N: DName> PartialOrd<N> for DNameBuf
[src]
fn partial_cmp(&self, other: &N) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for DNameBuf
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
ord_max_min
)Compares and returns the minimum of two values. Read more
impl Hash for DNameBuf
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more