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>
impl<Name, Data> Record<Name, Data>
sourcepub fn new(owner: Name, class: Class, ttl: Ttl, data: Data) -> Self
pub fn new(owner: Name, class: Class, ttl: Ttl, data: Data) -> Self
Creates a new record from its parts.
sourcepub fn from_record<NN, DD>(record: Record<NN, DD>) -> Selfwhere
Name: From<NN>,
Data: From<DD>,
pub fn from_record<NN, DD>(record: Record<NN, DD>) -> Selfwhere 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,
sourcepub fn owner(&self) -> &Name
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.
sourcepub fn rtype(&self) -> Rtypewhere
Data: RecordData,
pub fn rtype(&self) -> Rtypewhere Data: RecordData,
Returns the record type.
sourcepub fn into_owner_and_data(self) -> (Name, Data)
pub fn into_owner_and_data(self) -> (Name, Data)
Trades the record for its owner name and data.
source§impl<Octs, Data> Record<ParsedDname<Octs>, Data>
impl<Octs, Data> Record<ParsedDname<Octs>, Data>
Parsing and Composing
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: ToDname, D: RecordData + ComposeRecordData> Record<N, D>
impl<N: ToDname, D: RecordData + ComposeRecordData> Record<N, D>
pub fn compose<Target: Composer + ?Sized>( &self, target: &mut Target ) -> Result<(), Target::AppendError>
pub fn compose_canonical<Target: Composer + ?Sized>( &self, target: &mut Target ) -> Result<(), Target::AppendError>
Trait Implementations§
source§impl<N, NN, D, DD> CanonicalOrd<Record<NN, DD>> for Record<N, D>where
N: ToDname,
NN: ToDname,
D: RecordData + CanonicalOrd<DD>,
DD: RecordData,
impl<N, NN, D, DD> CanonicalOrd<Record<NN, DD>> for Record<N, D>where N: ToDname, NN: ToDname, D: RecordData + CanonicalOrd<DD>, DD: RecordData,
source§fn canonical_cmp(&self, other: &Record<NN, DD>) -> Ordering
fn canonical_cmp(&self, other: &Record<NN, DD>) -> Ordering
self
and other
.source§fn canonical_lt(&self, other: &Rhs) -> bool
fn canonical_lt(&self, other: &Rhs) -> bool
self
is canonically less than other
.source§fn canonical_le(&self, other: &Rhs) -> bool
fn canonical_le(&self, other: &Rhs) -> bool
self
is canonically less than or equal to other
.source§fn canonical_gt(&self, other: &Rhs) -> bool
fn canonical_gt(&self, other: &Rhs) -> bool
self
is canonically greater than other
.source§fn canonical_ge(&self, other: &Rhs) -> bool
fn canonical_ge(&self, other: &Rhs) -> bool
self
is canonically greater than or equal to other
.source§impl<Name, Data> ComposeRecord for Record<Name, Data>where
Name: ToDname,
Data: ComposeRecordData,
impl<Name, Data> ComposeRecord for Record<Name, Data>where Name: ToDname, Data: ComposeRecordData,
fn compose_record<Target: Composer + ?Sized>( &self, target: &mut Target ) -> Result<(), Target::AppendError>
source§impl<Name, Data> Display for Record<Name, Data>where
Name: Display,
Data: RecordData + Display,
impl<Name, Data> Display for Record<Name, Data>where Name: Display, Data: RecordData + Display,
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>,
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>,
type Error = <Data as OctetsFrom<SrcData>>::Error
source§impl<N, D> Ord for Record<N, D>where
N: Ord,
D: RecordData + Ord,
impl<N, D> Ord for Record<N, D>where N: Ord, D: RecordData + Ord,
source§impl<N, NN, D, DD> PartialEq<Record<NN, DD>> for Record<N, D>where
N: PartialEq<NN>,
D: RecordData + PartialEq<DD>,
DD: RecordData,
impl<N, NN, D, DD> PartialEq<Record<NN, DD>> for Record<N, D>where N: PartialEq<NN>, D: RecordData + PartialEq<DD>, DD: RecordData,
source§impl<N, NN, D, DD> PartialOrd<Record<NN, DD>> for Record<N, D>where
N: PartialOrd<NN>,
D: RecordData + PartialOrd<DD>,
DD: RecordData,
impl<N, NN, D, DD> PartialOrd<Record<NN, DD>> for Record<N, D>where N: PartialOrd<NN>, D: RecordData + PartialOrd<DD>, DD: RecordData,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more