Struct QueryBuilder

Source
pub struct QueryBuilder { /* private fields */ }
Expand description

Builds a query DNS message.

You can create a new query from a given question using the new function. The add_opt method provides the means to add an OPT record to the additional section. The entire additional section can later be removed through the revert_additional function.

Once you are happy with your query, you can turn it into a QueryMessage through the freeze method.

Implementations§

Source§

impl QueryBuilder

Source

pub fn new<N: ToDname, Q: Into<Question<N>>>(question: Q) -> Self

Creates a new query builder.

The query will contain one question built from question. It will have a random ID. The RD bit will not be set. If you desire recursion, you can enable it via the set_rd method.

Source

pub fn header(&self) -> &Header

Returns a reference to the header of the query.

Source

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

Returns a mutable reference to the header of the query.

Source

pub fn set_rd(&mut self, value: bool)

Sets the ‘recursion desired’ (RD) bit to the given value.

This is a shortcut to self.header_mut().set_rd(value).

By default, this bit is not set.

Source

pub fn add_opt<F>(&mut self, op: F)
where F: FnOnce(&mut OptBuilder<'_>),

Adds an OPT record to the additional section.

The content of the record can be manipulated in the closure provided as an argument. This closure receives a mutable reference to an OptBuilder which will allow access to the OPT record’s header as well as allow adding options.

Source

pub fn revert_additional(&mut self)

Removes all records from the additional section.

Afterwards, only the single question will remain in the message.

Source

pub fn freeze(self) -> QueryMessage

Freezes the query builder into a query message.

Trait Implementations§

Source§

impl Clone for QueryBuilder

Source§

fn clone(&self) -> QueryBuilder

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 Debug for QueryBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<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.