Struct Record

Source
pub struct Record<N: ToDname, D: RecordData> { /* private fields */ }
Expand description

A DNS resource record.

All information available through the DNS is stored in resource records. They have a three part key of a domain name, resource record type, and class. Data is arranged in a tree which is navigated using the domain name. Each node in the tree carries a label, starting with the root label as the top-most node. The tree is traversed by stepping through the name from right to left, finding a child node carring the label of each step. The domain name resulting from this traversal is part of the record itself. It is called the owner of the record.

The record type describes the kind of data the record holds, such as IP addresses. The class, finally, describes which sort of network the information is for since DNS was originally intended to be used for networks other than the Internet as well. In practice, the only relevant class is IN, the Internet. Note that each class has its own tree of nodes.

The payload of a resource record is its data. Its purpose, meaning, and format is determined by the record type (technically, also its class). For each unique three-part key there can be multiple resource records. All these records for the same key are called resource record sets, most often shortened to ‘RRset.’

There is one more piece of data: the TTL or time to live. This value says how long a record remains valid before it should be refreshed from its original source, given in seconds. The TTL is used to add caching facilities to the DNS.

Values of the Record type represent one single resource record. Since there are currently more than eighty record types—see Rtype for a complete list—, the type is generic over a trait for record data. This trait holds both the record type value and the record data as they are inseparably entwined.

Because a record’s owner is a domain name, the Record type is additionally generic over the domain name type is for it.

There is three ways to create a record value. First, you can make one yourself using the new function. It will neatly take care of all the generics through type inference. Secondly, you can parse a record from an existing message. Message and its friends provide a way to do that; see there for all the details. Finally, you can scan a record from master data (aka zonefiles). See the domain::master module for that.

Records can be place into DNS messages by using a MessageBuilder. In order to make adding records easier, Record implements the From trait for two kinds of tuples: A four-tuple of owner, class, time-to-live value, and record data and a triple leaving out the class and assuming it to be Class::In.

Implementations§

Source§

impl<N: ToDname, D: RecordData> Record<N, D>

§Creation and Element Access

Source

pub fn new(owner: N, class: Class, ttl: u32, data: D) -> Self

Creates a new record from its parts.

Source

pub fn owner(&self) -> &N

Returns a reference to owner domain name.

The owner of a record is the domain name that specifies the node in the DNS tree this record belongs to.

Source

pub fn rtype(&self) -> Rtype
where D: RecordData,

Returns the record type.

Source

pub fn class(&self) -> Class

Returns the record class.

Source

pub fn set_class(&mut self, class: Class)

Sets the record’s class.

Source

pub fn ttl(&self) -> u32

Returns the record’s time-to-live.

Source

pub fn set_ttl(&mut self, ttl: u32)

Sets the record’s time-to-live.

Source

pub fn data(&self) -> &D

Return a reference to the record data.

Source

pub fn data_mut(&mut self) -> &mut D

Returns a mutable reference to the record data.

Source

pub fn into_data(self) -> D

Trades the record for its record data.

Trait Implementations§

Source§

impl<N: Clone + ToDname, D: Clone + RecordData> Clone for Record<N, D>

Source§

fn clone(&self) -> Record<N, D>

Returns a duplicate 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<N: ToDname, D: RecordData> Compose for Record<N, D>

Source§

fn compose_len(&self) -> usize

Returns the number of bytes this value will need without compression.
Source§

fn compose<B: BufMut>(&self, buf: &mut B)

Appends the uncompressed representation of this value to buf. Read more
Source§

impl<N: ToDname, D: RecordData + Compress> Compress for Record<N, D>

Source§

fn compress(&self, buf: &mut Compressor) -> Result<(), ShortBuf>

Appends the wire-format representation of the value to buf. Read more
Source§

impl<N: Debug + ToDname, D: Debug + RecordData> Debug for Record<N, D>

Source§

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

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

impl<N, D> Display for Record<N, D>
where N: ToDname + Display, D: RecordData + Display,

Source§

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

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

impl<N: ToDname, D: RecordData> From<(N, Class, u32, D)> for Record<N, D>

Source§

fn from((owner, class, ttl, data): (N, Class, u32, D)) -> Self

Converts to this type from the input type.
Source§

impl<N: ToDname, D: RecordData> From<(N, u32, D)> for Record<N, D>

Source§

fn from((owner, ttl, data): (N, u32, D)) -> Self

Converts to this type from the input type.
Source§

impl<N: ToDname> From<Record<N, Opt>> for OptRecord

Source§

fn from(record: Record<N, Opt>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<N, D> Freeze for Record<N, D>
where N: Freeze, D: Freeze,

§

impl<N, D> RefUnwindSafe for Record<N, D>

§

impl<N, D> Send for Record<N, D>
where N: Send, D: Send,

§

impl<N, D> Sync for Record<N, D>
where N: Sync, D: Sync,

§

impl<N, D> Unpin for Record<N, D>
where N: Unpin, D: Unpin,

§

impl<N, D> UnwindSafe for Record<N, D>
where N: UnwindSafe, D: 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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.