Struct domain::base::name::NameBuilder

source ·
pub struct NameBuilder<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> NameBuilder<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, RelativeNameError>
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 NameBuilder<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 NameBuilder<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]>> NameBuilder<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> NameBuilder<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_dec_u8_label(&mut self, value: u8) -> Result<(), PushError>

Appends a label with the decimal representation of u8.

If there currently is a label under construction, it will be ended before appending label.

Returns an error if appending would result in a name longer than 254 bytes.

source

pub fn append_hex_digit_label(&mut self, nibble: u8) -> Result<(), PushError>

Appends a label with the hex digit.

If there currently is a label under construction, it will be ended before appending label.

Returns an error if appending would result in a name longer than 254 bytes.

source

pub fn append_name<N: ToRelativeName>( &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) -> RelativeName<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_name which appends the root label before finishing.

source

pub fn into_name(self) -> Result<Name<Builder::Octets>, PushError>
where Builder: FreezeBuilder,

Appends the root label to the name and returns it as a Name.

If there currently is a label under construction, ends the label. Then adds the empty root label and transforms the name into a Name.

source

pub fn append_origin<N: ToName>( self, origin: &N, ) -> Result<Name<Builder::Octets>, PushNameError>
where Builder: FreezeBuilder,

Appends an origin and returns the resulting Name.

If there currently is a label under construction, ends the label. Then adds the origin and transforms the name into a Name.

Trait Implementations§

source§

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

source§

fn clone(&self) -> NameBuilder<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 NameBuilder<Builder>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<Builder> UnwindSafe for NameBuilder<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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more