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>

source

pub fn new() -> Self
where Builder: EmptyBuilder,

Creates a new, empty name builder.

source

pub fn with_capacity(capacity: usize) -> Self
where Builder: EmptyBuilder,

Creates a new, empty builder with a given capacity.

source

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

source

pub fn new_vec() -> Self

Creates an empty domain name builder atop a Vec<u8>.

source

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>

source

pub fn new_bytes() -> Self

Creates an empty domain name bulider atop a bytes value.

source

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>

source

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

Returns the already assembled domain name as an octets slice.

source

pub fn len(&self) -> usize

Returns the length of the already assembled domain name.

source

pub fn is_empty(&self) -> bool

Returns whether the name is still empty.

source§

impl<Builder> DnameBuilder<Builder>
where Builder: OctetsBuilder + AsRef<[u8]> + AsMut<[u8]>,

source

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.

source

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.

source

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.

source

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.

source

pub fn end_label(&mut self)

Ends the current label.

If there isn’t a current label, does nothing.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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: AsRef<[u8]>> AsRef<[u8]> for DnameBuilder<Builder>

source§

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

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

impl<Builder: Clone> Clone for DnameBuilder<Builder>

source§

fn clone(&self) -> DnameBuilder<Builder>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Builder: EmptyBuilder> Default for DnameBuilder<Builder>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Builder> Freeze for DnameBuilder<Builder>
where Builder: Freeze,

§

impl<Builder> RefUnwindSafe for DnameBuilder<Builder>
where Builder: RefUnwindSafe,

§

impl<Builder> Send for DnameBuilder<Builder>
where Builder: Send,

§

impl<Builder> Sync for DnameBuilder<Builder>
where Builder: Sync,

§

impl<Builder> Unpin for DnameBuilder<Builder>
where Builder: Unpin,

§

impl<Builder> UnwindSafe for DnameBuilder<Builder>
where Builder: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

source§

type Error = <Target as OctetsFrom<Source>>::Error

source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V