Struct domain::base::message_builder::AdditionalBuilder

source ·
pub struct AdditionalBuilder<Target> { /* private fields */ }
Expand description

Builds the additional section of a DNS message.

A value of this type can be acquired by calling the additional method on any other builder type. See the module documentation for an overview of how to build a message.

You can push records to the end of the additional section via the push method. It accepts various things that represent resource records: record values and references, tuples of an owner domain name, a class, TTL, and record data, as well as tuples of just the owner, TTL, and data, assuming the class of IN.

A special method exists to make adding an OPT record to the section easier. The opt method creates an OptBuilder and passes it to a closure. This way, you can add and remove OPT records from additional builders that are part of another type and cannot be traded in easily.

Once you are finished building the additional section, you can finish the message via finish. Additionally, conversions to all other builder types are available as well.

Implementations§

source§

impl<Target: Composer> AdditionalBuilder<Target>

source

pub fn push(&mut self, record: impl ComposeRecord) -> Result<(), PushError>

Appends a record to the additional section.

This methods accepts anything that implements the ComposeRecord trait. Apart from record values and references, this are tuples of the owner domain name, optionally the class (which is taken to be IN if missing), the TTL, and record data.

In other words, you can do the following things:

use domain::base::{Dname, MessageBuilder, Record, Rtype, Ttl};
use domain::base::iana::Class;
use domain::rdata::A;

let mut msg = MessageBuilder::new_vec().additional();
let record = Record::new(
    Dname::root_ref(), Class::In, Ttl::from_secs(86400), A::from_octets(192, 0, 2, 1)
);
msg.push(&record).unwrap();
msg.push(record).unwrap();
msg.push(
    (Dname::root_ref(), Class::In, 86400, A::from_octets(192, 0, 2, 1))
).unwrap();
msg.push(
    (Dname::root_ref(), 86400, A::from_octets(192, 0, 2, 1))
).unwrap();
source§

impl<Target: Composer> AdditionalBuilder<Target>

source

pub fn opt<F>(&mut self, op: F) -> Result<(), PushError>
where F: FnOnce(&mut OptBuilder<'_, Target>) -> Result<(), Target::AppendError>,

Appends and builds an OPT record.

The actual building of the record is handled by a closure that receives an OptBuilder which can both change the header of the record and add options.

The method will return whatever the closure returns. In addition, it will return an error if it failed to add the header of the OPT record.

source§

impl<Target: Composer> AdditionalBuilder<Target>

§Conversions

Additional conversion methods are available via the Deref implementation.

source

pub fn rewind(&mut self)

Rewinds to an empty additional section.

All previously added additional records will be lost.

source

pub fn builder(self) -> MessageBuilder<Target>

Converts the additional builder into a message builder.

All questions and records will be dropped and all sections will be empty.

source

pub fn question(self) -> QuestionBuilder<Target>

Converts the additional builder into a question builder.

All answer, authority, and additional records will be dropped. All previously added questions will, however, remain.

source

pub fn answer(self) -> AnswerBuilder<Target>

Converts the additional builder into an answer builder.

All authority and additional records will be dropped. All questions and answer records will remain.

source

pub fn authority(self) -> AuthorityBuilder<Target>

Converts the additional builder into an authority builder.

All additional records will be dropped. All questions, answer, and authority records will remain.

source§

impl<Target: Composer> AdditionalBuilder<Target>

source

pub fn additional(self) -> AdditionalBuilder<Target>

Converts the additional builder into an additional builder.

In other words, does absolutely nothing.

source

pub fn finish(self) -> Target

Converts the additional builder into the underlying octets builder.

source

pub fn into_message(self) -> Message<Target::Octets>
where Target: FreezeBuilder,

Converts the additional builder into the final message.

The method will return a message atop whatever octets sequence the builder’s octets builder converts into.

source§

impl<Target> AdditionalBuilder<Target>

source

pub fn as_builder(&self) -> &MessageBuilder<Target>

Returns a reference to the underlying message builder.

source

pub fn as_builder_mut(&mut self) -> &mut MessageBuilder<Target>

Returns a mutable reference to the underlying message builder.

Methods from Deref<Target = MessageBuilder<Target>>§

source

pub fn header(&self) -> Header

Return the current value of the message header.

source

pub fn counts(&self) -> HeaderCounts

Return the current value of the message header counts.

source

pub fn header_mut(&mut self) -> &mut Header

Returns a mutable reference to the message header for manipulations.

source

pub fn as_target(&self) -> &Target

Returns a reference to the underlying octets builder.

source

pub fn as_slice(&self) -> &[u8]
where Target: AsRef<[u8]>,

Returns an octets slice of the octets assembled so far.

source

pub fn as_message(&self) -> Message<&[u8]>
where Target: AsRef<[u8]>,

Returns a message atop for the octets assembled so far.

This message is atop the octets slices derived from the builder, so it can be created cheaply.

Trait Implementations§

source§

impl<Target> AsMut<MessageBuilder<Target>> for AdditionalBuilder<Target>

source§

fn as_mut(&mut self) -> &mut MessageBuilder<Target>

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

impl<Target: AsRef<[u8]>> AsRef<[u8]> for AdditionalBuilder<Target>

source§

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

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

impl<Target> AsRef<MessageBuilder<Target>> for AdditionalBuilder<Target>

source§

fn as_ref(&self) -> &MessageBuilder<Target>

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

impl<Target> AsRef<Target> for AdditionalBuilder<Target>

source§

fn as_ref(&self) -> &Target

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

impl<Target: Clone> Clone for AdditionalBuilder<Target>

source§

fn clone(&self) -> AdditionalBuilder<Target>

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<Target: Debug> Debug for AdditionalBuilder<Target>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Target> Deref for AdditionalBuilder<Target>

§

type Target = MessageBuilder<Target>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<Target> DerefMut for AdditionalBuilder<Target>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<Target> From<AdditionalBuilder<Target>> for AnswerBuilder<Target>
where Target: Composer,

source§

fn from(src: AdditionalBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<AdditionalBuilder<Target>> for AuthorityBuilder<Target>
where Target: Composer,

source§

fn from(src: AdditionalBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<AdditionalBuilder<Target>> for MessageBuilder<Target>
where Target: Composer,

source§

fn from(src: AdditionalBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<AdditionalBuilder<Target>> for QuestionBuilder<Target>
where Target: Composer,

source§

fn from(src: AdditionalBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<AnswerBuilder<Target>> for AdditionalBuilder<Target>
where Target: Composer,

source§

fn from(src: AnswerBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<AuthorityBuilder<Target>> for AdditionalBuilder<Target>
where Target: Composer,

source§

fn from(src: AuthorityBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<MessageBuilder<Target>> for AdditionalBuilder<Target>
where Target: Composer,

source§

fn from(src: MessageBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> From<QuestionBuilder<Target>> for AdditionalBuilder<Target>
where Target: Composer,

source§

fn from(src: QuestionBuilder<Target>) -> Self

Converts to this type from the input type.
source§

impl<Target> RecordSectionBuilder<Target> for AdditionalBuilder<Target>
where Target: Composer,

source§

fn push(&mut self, record: impl ComposeRecord) -> Result<(), PushError>

Appends a record to a record section. Read more

Auto Trait Implementations§

§

impl<Target> Freeze for AdditionalBuilder<Target>
where Target: Freeze,

§

impl<Target> RefUnwindSafe for AdditionalBuilder<Target>
where Target: RefUnwindSafe,

§

impl<Target> Send for AdditionalBuilder<Target>
where Target: Send,

§

impl<Target> Sync for AdditionalBuilder<Target>
where Target: Sync,

§

impl<Target> Unpin for AdditionalBuilder<Target>
where Target: Unpin,

§

impl<Target> UnwindSafe for AdditionalBuilder<Target>
where Target: 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> 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>,

§

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,

§

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

§

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

§

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