Struct domain::base::name::DnameBuilder
source · pub struct DnameBuilder<Builder> { /* private fields */ }
Expand description
Builds a domain name step by step by appending data.
The domain name builder is the most fundamental way to construct a new domain name. It wraps an octets builder that assembles the name step by step.
The methods push
and append_slice
to add the octets of a label to end of the builder. Once a label is
complete, end_label
finishes the current label and
starts a new one.
The method append_label
combines this process
and appends the given octets as a label.
The name builder currently is not aware of internationalized domain names. The octets passed to it are used as is and are not converted.
Implementations§
source§impl<Builder> DnameBuilder<Builder>
impl<Builder> DnameBuilder<Builder>
sourcepub fn new() -> Selfwhere
Builder: EmptyBuilder,
pub fn new() -> Selfwhere Builder: EmptyBuilder,
Creates a new, empty name builder.
sourcepub fn with_capacity(capacity: usize) -> Selfwhere
Builder: EmptyBuilder,
pub fn with_capacity(capacity: usize) -> Selfwhere Builder: EmptyBuilder,
Creates a new, empty builder with a given capacity.
sourcepub fn from_builder(builder: Builder) -> Result<Self, RelativeDnameError>where
Builder: OctetsBuilder + AsRef<[u8]>,
pub fn from_builder(builder: Builder) -> Result<Self, RelativeDnameError>where Builder: OctetsBuilder + AsRef<[u8]>,
Creates a new domain name builder atop an existing octets builder.
The function checks that whatever is in the builder already consititutes a correctly encoded relative domain name.
source§impl DnameBuilder<Vec<u8>>
impl DnameBuilder<Vec<u8>>
sourcepub fn vec_with_capacity(capacity: usize) -> Self
pub fn vec_with_capacity(capacity: usize) -> Self
Creates an empty builder atop a Vec<u8>
with given capacity.
Names are limited to a length of 255 octets, but you can provide any capacity you like here.
source§impl DnameBuilder<BytesMut>
impl DnameBuilder<BytesMut>
sourcepub fn bytes_with_capacity(capacity: usize) -> Self
pub fn bytes_with_capacity(capacity: usize) -> Self
Creates an empty bulider atop a bytes value with given capacity.
Names are limited to a length of 255 octets, but you can provide any capacity you like here.
source§impl<Builder: AsRef<[u8]>> DnameBuilder<Builder>
impl<Builder: AsRef<[u8]>> DnameBuilder<Builder>
source§impl<Builder> DnameBuilder<Builder>where
Builder: OctetsBuilder + AsRef<[u8]> + AsMut<[u8]>,
impl<Builder> DnameBuilder<Builder>where Builder: OctetsBuilder + AsRef<[u8]> + AsMut<[u8]>,
sourcepub fn in_label(&self) -> bool
pub fn in_label(&self) -> bool
Returns whether there currently is a label under construction.
This returns false
if the name is still empty or if the last thing
that happend was a call to end_label
.
sourcepub fn push(&mut self, ch: u8) -> Result<(), PushError>
pub fn push(&mut self, ch: u8) -> Result<(), PushError>
Pushes an octet to the end of the domain name.
Starts a new label if necessary. Returns an error if pushing the octet would exceed the size limits for labels or domain names.
sourcepub fn push_symbol(&mut self, sym: Symbol) -> Result<(), FromStrError>
pub fn push_symbol(&mut self, sym: Symbol) -> Result<(), FromStrError>
Pushes a symbol to the end of the domain name.
The symbol is iterpreted as part of the presentation format of a domain name, i.e., an unescaped dot is considered a label separator.
sourcepub fn append_slice(&mut self, slice: &[u8]) -> Result<(), PushError>
pub fn append_slice(&mut self, slice: &[u8]) -> Result<(), PushError>
Appends the content of an octets slice to the end of the domain name.
Starts a new label if necessary. Returns an error if pushing would exceed the size limits for labels or domain names.
If slice
is empty, does absolutely nothing.
sourcepub fn end_label(&mut self)
pub fn end_label(&mut self)
Ends the current label.
If there isn’t a current label, does nothing.
sourcepub fn append_label(&mut self, label: &[u8]) -> Result<(), PushError>
pub fn append_label(&mut self, label: &[u8]) -> Result<(), PushError>
Appends an octets slice as a complete label.
If there currently is a label under construction, it will be ended
before appending label
.
Returns an error if label
exceeds the label size limit of 63 bytes
or appending the label would exceed the domain name size limit of
255 bytes.
sourcepub fn append_name<N: ToRelativeDname>(
&mut self,
name: &N
) -> Result<(), PushNameError>
pub fn append_name<N: ToRelativeDname>( &mut self, name: &N ) -> Result<(), PushNameError>
Appends a relative domain name.
If there currently is a label under construction, it will be ended
before appending name
.
Returns an error if appending would result in a name longer than 254 bytes.
sourcepub fn append_symbols<Sym: IntoIterator<Item = Symbol>>(
&mut self,
symbols: Sym
) -> Result<(), FromStrError>
pub fn append_symbols<Sym: IntoIterator<Item = Symbol>>( &mut self, symbols: Sym ) -> Result<(), FromStrError>
Appends a name from a sequence of symbols.
If there currently is a label under construction, it will be ended
before appending chars
.
The character sequence must result in a domain name in representation format. That is, its labels should be separated by dots, actual dots, white space, backslashes and byte values that are not printable ASCII characters should be escaped.
The last label will only be ended if the last character was a dot.
Thus, you can determine if that was the case via
in_label
.
sourcepub fn append_chars<C: IntoIterator<Item = char>>(
&mut self,
chars: C
) -> Result<(), FromStrError>
pub fn append_chars<C: IntoIterator<Item = char>>( &mut self, chars: C ) -> Result<(), FromStrError>
Appends a name from a sequence of characters.
If there currently is a label under construction, it will be ended
before appending chars
.
The character 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.
The last label will only be ended if the last character was a dot.
Thus, you can determine if that was the case via
in_label
.
sourcepub fn finish(self) -> RelativeDname<Builder::Octets>where
Builder: FreezeBuilder,
pub fn finish(self) -> RelativeDname<Builder::Octets>where Builder: FreezeBuilder,
Finishes building the name and returns the resulting relative name.
If there currently is a label being built, ends the label first
before returning the name. I.e., you don’t have to call end_label
explicitely.
This method converts the builder into a relative name. If you would
like to turn it into an absolute name, use into_dname
which
appends the root label before finishing.
sourcepub fn into_dname(self) -> Result<Dname<Builder::Octets>, PushError>where
Builder: FreezeBuilder,
pub fn into_dname(self) -> Result<Dname<Builder::Octets>, PushError>where Builder: FreezeBuilder,
Appends the root label to the name and returns it as a Dname
.
If there currently is a label under construction, ends the label.
Then adds the empty root label and transforms the name into a
Dname
.
sourcepub fn append_origin<N: ToDname>(
self,
origin: &N
) -> Result<Dname<Builder::Octets>, PushNameError>where
Builder: FreezeBuilder,
pub fn append_origin<N: ToDname>( self, origin: &N ) -> Result<Dname<Builder::Octets>, PushNameError>where Builder: FreezeBuilder,
Appends an origin and returns the resulting Dname
.
If there currently is a label under construction, ends the label.
Then adds the origin
and transforms the name into a
Dname
.
Trait Implementations§
source§impl<Builder: Clone> Clone for DnameBuilder<Builder>
impl<Builder: Clone> Clone for DnameBuilder<Builder>
source§fn clone(&self) -> DnameBuilder<Builder>
fn clone(&self) -> DnameBuilder<Builder>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more