Struct domain::base::record::Record

source ·
pub struct Record<Name, Data> { /* 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. The 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. 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 zone file format. See the crate’s zonefile module for that.

Implementations§

source§

impl<Name, Data> Record<Name, Data>

§Creation and Element Access

source

pub fn new(owner: Name, class: Class, ttl: Ttl, data: Data) -> Self

Creates a new record from its parts.

source

pub fn from_record<NN, DD>(record: Record<NN, DD>) -> Self
where Name: From<NN>, Data: From<DD>,

Creates a new record from a compatible record.

This function only exists because the equivalent From implementation is currently not possible,

source

pub fn owner(&self) -> &Name

Returns a reference to the 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 Data: 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) -> Ttl

Returns the record’s time-to-live.

source

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

Sets the record’s time-to-live.

source

pub fn data(&self) -> &Data

Return a reference to the record data.

source

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

Returns a mutable reference to the record data.

source

pub fn into_data(self) -> Data

Trades the record for its record data.

source

pub fn into_owner_and_data(self) -> (Name, Data)

Trades the record for its owner name and data.

source§

impl<Octs, Data> Record<ParsedName<Octs>, Data>

Parsing and Composing

source

pub fn parse<'a, Src: Octets<Range<'a> = Octs> + 'a>( parser: &mut Parser<'a, Src>, ) -> Result<Option<Self>, ParseError>
where Data: ParseRecordData<'a, Src>,

source§

impl<N: ToName, D: RecordData + ComposeRecordData> Record<N, D>

source

pub fn compose<Target: Composer + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

source

pub fn compose_canonical<Target: Composer + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

Trait Implementations§

source§

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

source§

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

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

impl<N, NN, D, DD> CanonicalOrd<Record<NN, DD>> for Record<N, D>
where N: ToName, NN: ToName, D: RecordData + CanonicalOrd<DD>, DD: RecordData,

source§

fn canonical_cmp(&self, other: &Record<NN, DD>) -> Ordering

Returns the canonical ordering between self and other.
source§

fn canonical_lt(&self, other: &Rhs) -> bool

Returns whether self is canonically less than other.
source§

fn canonical_le(&self, other: &Rhs) -> bool

Returns whether self is canonically less than or equal to other.
source§

fn canonical_gt(&self, other: &Rhs) -> bool

Returns whether self is canonically greater than other.
source§

fn canonical_ge(&self, other: &Rhs) -> bool

Returns whether self is canonically greater than or equal to other.
source§

impl<Name: Clone, Data: Clone> Clone for Record<Name, Data>

source§

fn clone(&self) -> Record<Name, Data>

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<Name, Data> ComposeRecord for Record<Name, Data>
where Name: ToName, Data: ComposeRecordData,

source§

fn compose_record<Target: Composer + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

source§

impl<Name, Data> Debug for Record<Name, Data>
where Name: Debug, Data: Debug,

source§

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

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

impl<Name, Data> Display for Record<Name, Data>
where Name: Display, Data: RecordData + Display,

source§

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

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

impl<Name, TName, Data, TData> FlattenInto<Record<TName, TData>> for Record<Name, Data>
where Name: FlattenInto<TName>, Data: FlattenInto<TData, AppendError = Name::AppendError>,

source§

type AppendError = <Name as FlattenInto<TName>>::AppendError

source§

fn try_flatten_into(self) -> Result<Record<TName, TData>, Name::AppendError>

source§

impl<N, D> From<(N, Class, Ttl, D)> for Record<N, D>

source§

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

Converts to this type from the input type.
source§

impl<N, D> 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, D> 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<Octs, N: ToName> From<Record<N, Opt<Octs>>> for OptRecord<Octs>

source§

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

Converts to this type from the input type.
source§

impl<Name, Data> Hash for Record<Name, Data>
where Name: Hash, Data: Hash,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<Name, Data, SrcName, SrcData> OctetsFrom<Record<SrcName, SrcData>> for Record<Name, Data>
where Name: OctetsFrom<SrcName>, Data: OctetsFrom<SrcData>, Data::Error: From<Name::Error>,

source§

type Error = <Data as OctetsFrom<SrcData>>::Error

source§

fn try_octets_from( source: Record<SrcName, SrcData>, ) -> Result<Self, Self::Error>

Performs the conversion.
source§

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

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<N, NN, D, DD> PartialEq<Record<NN, DD>> for Record<N, D>
where N: PartialEq<NN>, D: RecordData + PartialEq<DD>, DD: RecordData,

source§

fn eq(&self, other: &Record<NN, DD>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<N, NN, D, DD> PartialOrd<Record<NN, DD>> for Record<N, D>
where N: PartialOrd<NN>, D: RecordData + PartialOrd<DD>, DD: RecordData,

source§

fn partial_cmp(&self, other: &Record<NN, DD>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<N: Eq, D: RecordData + Eq> Eq for Record<N, D>

Auto Trait Implementations§

§

impl<Name, Data> Freeze for Record<Name, Data>
where Name: Freeze, Data: Freeze,

§

impl<Name, Data> RefUnwindSafe for Record<Name, Data>
where Name: RefUnwindSafe, Data: RefUnwindSafe,

§

impl<Name, Data> Send for Record<Name, Data>
where Name: Send, Data: Send,

§

impl<Name, Data> Sync for Record<Name, Data>
where Name: Sync, Data: Sync,

§

impl<Name, Data> Unpin for Record<Name, Data>
where Name: Unpin, Data: Unpin,

§

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

source§

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