domain::base::message_builder

Struct MessageBuilder

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

Starts building a DNS message.

This type wraps an OctetsBuilder and starts the process of building a message. It allows access to the header section. The message builder can be traded in for any section builder or the underlying octets builder.

For more details see the module documentation.

Implementations§

source§

impl<Target: OctetsBuilder + Truncate> MessageBuilder<Target>

§Creating Message Builders

source

pub fn from_target(target: Target) -> Result<Self, Target::AppendError>

Creates a new message builder using the given target.

The target must be an OctetsBuilder. It will be truncated to zero size before appending the header section. That is, all data that was in the builder before will be lost.

The function will result in an error if the builder doesn’t have enough space for the header section.

source§

impl MessageBuilder<Vec<u8>>

source

pub fn new_vec() -> Self

Creates a new message builder atop a Vec<u8>.

source§

impl MessageBuilder<StreamTarget<Vec<u8>>>

source

pub fn new_stream_vec() -> Self

Creates a new builder for a streamable message atop a Vec<u8>.

source§

impl MessageBuilder<BytesMut>

source

pub fn new_bytes() -> Self

Creates a new message builder atop a bytes value.

source§

impl MessageBuilder<StreamTarget<BytesMut>>

source

pub fn new_stream_bytes() -> Self

Creates a new streamable message builder atop a bytes value.

source§

impl<Target: Composer> MessageBuilder<Target>

source

pub fn start_answer<Octs: Octets + ?Sized>( self, msg: &Message<Octs>, rcode: Rcode, ) -> Result<AnswerBuilder<Target>, PushError>

Starts creating an answer for the given message.

Specifically, this sets the ID, QR, OPCODE, RD, and RCODE fields in the header and attempts to push the message’s questions to the builder.

The method converts the message builder into an answer builder ready to receive the answer for the question.

source

pub fn start_error<Octs: Octets + ?Sized>( self, msg: &Message<Octs>, rcode: Rcode, ) -> AnswerBuilder<Target>

Starts creating an error for the given message.

Like start_answer() but infallible. Questions will be pushed if possible.

source

pub fn request_axfr<N: ToName>( self, apex: N, ) -> Result<AnswerBuilder<Target>, PushError>

Creates an AXFR request for the given domain.

Sets a random ID, pushes the domain and the AXFR record type into the question section, and converts the builder into an answer builder.

source§

impl<Target: Composer> MessageBuilder<Target>

§Limiting message size

source

pub fn set_push_limit(&mut self, limit: usize)

Limit how much of the underlying buffer may be used.

When a limit is set, calling push() on a message section (e.g. AdditionalBuilder::push()) will fail if the limit is exceeded just as if the actual end of the underlying buffer had been reached.

Note: Calling this function does NOT truncate the underlying buffer. If the new limit is lees than the amount of the buffer that has already been used, exisitng content beyond the limit will remain untouched, the length will remain larger than the limit, and calls to push() will fail until the buffer is truncated to a size less than the limit.

source

pub fn clear_push_limit(&mut self)

Clear the push limit, if set.

Removes any push limit previously set via [set_push_limit()].

source

pub fn push_limit(&self) -> Option<usize>

Returns the current push limit, if set.

source§

impl<Target: OctetsBuilder + AsRef<[u8]>> MessageBuilder<Target>

§Access to the Message Header

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§

impl<Target: OctetsBuilder + AsMut<[u8]>> MessageBuilder<Target>

source

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

Returns a mutable reference to the message header for manipulations.

source§

impl<Target> MessageBuilder<Target>

§Conversions

source

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

Converts the message builder into a message builder

This is a no-op.

source§

impl<Target: Composer> MessageBuilder<Target>

source

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

Converts the message builder into a question builder.

source

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

Converts the message builder into an answer builder.

This will leave the question section empty.

source

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

Converts the message builder into an authority builder.

This will leave the question and answer sections empty.

source

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

Converts the message builder into an additional builder.

This will leave the question, answer, and authority sections empty.

source

pub fn finish(self) -> Target

Converts the message into the underlying octets builder.

This will leave the all sections empty.

source§

impl<Target: FreezeBuilder> MessageBuilder<Target>

source

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

Converts the builder into a message.

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

source§

impl<Target> MessageBuilder<Target>

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> AsMut<MessageBuilder<Target>> for AnswerBuilder<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> AsMut<MessageBuilder<Target>> for AuthorityBuilder<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> AsMut<MessageBuilder<Target>> for QuestionBuilder<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 MessageBuilder<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<MessageBuilder<Target>> for AnswerBuilder<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<MessageBuilder<Target>> for AuthorityBuilder<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<MessageBuilder<Target>> for QuestionBuilder<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 MessageBuilder<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 MessageBuilder<Target>

source§

fn clone(&self) -> MessageBuilder<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 MessageBuilder<Target>

source§

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

Formats the value using the given formatter. Read more
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<AnswerBuilder<Target>> for MessageBuilder<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 MessageBuilder<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<MessageBuilder<Target>> for AnswerBuilder<Target>
where Target: Composer,

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl<Target> From<MessageBuilder<Target>> for Message<Target::Octets>
where Target: FreezeBuilder,

source§

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

Converts to this type from the input type.
source§

impl<Target> From<MessageBuilder<Target>> for QuestionBuilder<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 MessageBuilder<Target>
where Target: Composer,

source§

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

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<Target> UnwindSafe for MessageBuilder<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> 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