Skip to main content

DName

Struct DName 

Source
#[repr(transparent)]
pub struct DName { pub name: Name, }
Available on crate feature unstable-new only.
Expand description

Redirection for the descendants of this domain.

A DName record indicates that a doamin name is a (partial!) alias. Queries for data under that domain name (not that domain name itself) are redirected to the specified target. A domain name can have at most one DName record; in this case, it cannot define subordinate records nor have a CName record. It is conceptually similar to CName.

DName is specified by RFC 6672.

§Wire Format

The wire format of a DName record is simply the target domain name. This domain name cannot be compressed in DNS messages.

The memory layout of the DName type is identical to its serialization in the wire format. This means that it can be parsed from the wire format in a zero-copy fashion, which is more efficient.

§Usage

Because DName is a record data type, it is usually handled within an enum like RecordData. This section describes how to use it independently (or when building new record data from scratch).

DName is a dynamically sized type (DST). It is not possible to store an DName in place (e.g. in a local variable); it must be held indirectly, via a reference or a smart pointer type like Box. This makes it more difficult to create new DNames; but once they are placed somewhere, they can be used by reference (i.e. &DName) exactly like any other type.

It is currently a bit difficult to build a new DName from scratch. It is easiest to use DName::new() on a reference to a Name, or to build the wire format representation of the DName manually and then to parse it.

// Parse a 'Name' and build a 'DName' from there:
let name = "example.org.".parse::<NameBuf>().unwrap();
let dname = DName::new(&name);

// Parse a 'DName' from the DNS wire format:
let bytes = b"\x07example\x03org\x00";
let from_bytes: &DName = <&DName>::parse_bytes(bytes).unwrap();
assert_eq!(dname.as_bytes(), bytes);

// Copy a 'DName' onto the heap:
let heaped: Box<DName> = dname.unsized_copy_into();

As a DST, DName does not implement Copy or Clone. Instead, it implements UnsizedCopy. A DName, held by reference, can be copied into a different container (e.g. Box) using unsized_copy_into()

For debugging, DName can be formatted using fmt::Debug.

To serialize a DName in the wire format, use BuildBytes (which will serialize it to a given buffer) or AsBytes (which will cast the DName into a byte sequence in place). It also supports BuildInMessage.

Fields§

§name: Name

The target name.

Implementations§

Source§

impl DName

Source

pub const fn new(target: &Name) -> &Self

Wrap a domain name as a DName.

Trait Implementations§

Source§

impl AsBytes for DName

Source§

fn as_bytes(&self) -> &[u8]

Interpret this value as a sequence of bytes. Read more
Source§

impl BuildBytes for DName

Source§

fn build_bytes<'bytes>( &self, bytes: &'bytes mut [u8], ) -> Result<&'bytes mut [u8], TruncationError>

Serialize into a byte sequence. Read more
Source§

fn built_bytes_size(&self) -> usize

The size of self when serialized into a byte sequence. Read more
Source§

impl BuildInMessage for DName

Source§

fn build_in_message( &self, contents: &mut [u8], start: usize, compressor: &mut NameCompressor, ) -> Result<usize, TruncationError>

Write this object in a DNS message. Read more
Source§

impl CanonicalRecordData for DName

Source§

fn build_canonical_bytes<'b>( &self, bytes: &'b mut [u8], ) -> Result<&'b mut [u8], TruncationError>

Serialize record data in the canonical form. Read more
Source§

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

Compare record data in the canonical form. Read more
Source§

impl Debug for DName

Source§

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

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

impl Eq for DName

Source§

impl<'a, N> From<&'a DName> for RecordData<'a, N>

Source§

fn from(value: &'a DName) -> Self

Converts to this type from the input type.
Source§

impl Hash for DName

Source§

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

Feeds this value into the given Hasher. Read more
Source§

impl Ord for DName

Source§

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

This method returns an Ordering between self and other. Read more
Source§

impl ParseBytesZC for DName

Source§

fn parse_bytes_by_ref(bytes: &[u8]) -> Result<&Self, ParseError>

Interpret a byte sequence as an instance of Self. Read more
Source§

fn parse_bytes_in<C: ParseBytesInPlace>( container: C, ) -> Result<C::WithParsed<Self>, (C, ParseError)>

Parse bytes within the given container. Read more
Source§

impl<'a> ParseMessageBytes<'a> for &'a DName

Source§

fn parse_message_bytes( contents: &'a [u8], start: usize, ) -> Result<Self, ParseError>

Parse a value from bytes in a DNS message. Read more
Source§

impl<'a> ParseRecordData<'a> for &'a DName

Source§

fn parse_record_data( contents: &'a [u8], start: usize, rtype: RType, ) -> Result<Self, ParseError>

Parse DNS record data of the given type from a DNS message.
Source§

impl<'a> ParseRecordDataBytes<'a> for &'a DName

Source§

fn parse_record_data_bytes( bytes: &'a [u8], rtype: RType, ) -> Result<Self, ParseError>

Parse DNS record data of the given type from a byte sequence.
Source§

impl PartialEq for DName

Source§

fn eq(&self, other: &DName) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for DName

Source§

fn partial_cmp(&self, other: &DName) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 SplitBytesZC for DName

Source§

fn split_bytes_by_ref(bytes: &[u8]) -> Result<(&Self, &[u8]), ParseError>

Interpret the start of a byte sequence as an instance of Self. Read more
Source§

impl StructuralPartialEq for DName

Source§

impl UnsizedCopy for DName

Source§

type Alignment = (<Name as UnsizedCopy>::Alignment,)

A type with the same alignment as Self. Read more
Source§

fn ptr_with_addr(&self, addr: *const ()) -> *const Self

Change the address of a pointer to Self. Read more
Source§

fn unsized_copy_into<T: UnsizedCopyFrom<Source = Self>>(&self) -> T

Copy self into a new container. Read more

Auto Trait Implementations§

§

impl !Sized for DName

§

impl Freeze for DName

§

impl RefUnwindSafe for DName

§

impl Send for DName

§

impl Sync for DName

§

impl Unpin for DName

§

impl UnsafeUnpin for DName

§

impl UnwindSafe for DName

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.