MessageEncoder

Struct MessageEncoder 

Source
pub struct MessageEncoder<'a, S>
where S: Section,
{ /* private fields */ }

Implementations§

Source§

impl<'a, S> MessageEncoder<'a, S>
where S: Section,

Source

pub fn set_header(&mut self, header: Header)

Sets the message header.

Note that the MessageEncoder will modify some header fields on drop, to ensure that the message can be parsed correctly.

Source

pub fn finish(self) -> Result<usize, Error>

Finishes encoding the packet, and returns the number of bytes that were written to the buffer.

If the message was truncated because the provided buffer was too small, this will return Error::Truncated, and the message’s truncation bit will be set. In that case, the user can still decide to send the message.

Source§

impl<'a> MessageEncoder<'a, Question>

Source

pub fn new(buf: &'a mut [u8]) -> MessageEncoder<'a, Question>

Creates a new message encoder that will write to buf.

Initially, the encoder will be in the Question state, in which questions can be appended to the message by calling MessageEncoder::question. The encoder can either be moved to the next section by calling the appropriate method, or be dropped, which will finish the encoded message.

§Panics

buf must be large enough to fit at least the message header (size_of::<Header>()), otherwise this function will panic.

Source

pub fn question(&mut self, question: Question<'_>)

Adds a question to the Question section.

Source

pub fn answers(self) -> MessageEncoder<'a, Answer>

Moves the encoder to the Answer section.

Source§

impl<'a> MessageEncoder<'a, Answer>

Source

pub fn add_answer(&mut self, rr: ResourceRecord<'_>)

Source

pub fn authority(self) -> MessageEncoder<'a, Authority>

Moves the encoder to the Authority section.

Source§

impl<'a> MessageEncoder<'a, Authority>

Source

pub fn add_authority(&mut self, rr: ResourceRecord<'_>)

Source

pub fn additional(self) -> MessageEncoder<'a, Additional>

Moves the encoder to the Additional Records section.

Source§

impl<'a> MessageEncoder<'a, Additional>

Source

pub fn add_additional(&mut self, rr: ResourceRecord<'_>)

Auto Trait Implementations§

§

impl<'a, S> Freeze for MessageEncoder<'a, S>

§

impl<'a, S> RefUnwindSafe for MessageEncoder<'a, S>
where S: RefUnwindSafe,

§

impl<'a, S> Send for MessageEncoder<'a, S>
where S: Send,

§

impl<'a, S> Sync for MessageEncoder<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for MessageEncoder<'a, S>
where S: Unpin,

§

impl<'a, S> !UnwindSafe for MessageEncoder<'a, S>

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