Skip to main content

Ptr

Struct Ptr 

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

A pointer to another domain name.

A Ptr record is used with special domain names for pointing to other locations in the domain name space. It is conventionally used for reverse lookups: for example, the Ptr record for <addr>.in-addr.arpa points to the domain name using the IPv4 <addr> in an A record. The same technique works with <addr>.ip6.arpa for IPv6 addresses.

Ptr is specified by RFC 1035, section 3.3.12.

§Wire format

The wire format of a Ptr record is simply the domain name of the name server. This domain name may be compressed in DNS messages.

§Usage

Because Ptr 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).

In order to build a Ptr, it’s first important to choose a domain name type. For short-term usage (where the Ptr is a local variable), it is common to pick RevNameBuf. If the Ptr will be placed on the heap, Box<RevName> will be more efficient.

The primary way to build a new Ptr is to construct each field manually. To parse a Ptr from a DNS message, use ParseMessageBytes. In case the input bytes don’t use name compression, ParseBytes can be used.

// Build a 'Ptr' manually:
let manual: Ptr<RevNameBuf> = Ptr {
    name: "example.org.".parse().unwrap(),
};

// Its wire format serialization looks like:
let bytes = b"\x07example\x03org\x00";

// Parse a 'Ptr' from the wire format, without name decompression:
let from_wire: Ptr<RevNameBuf> = Ptr::parse_bytes(bytes).unwrap();

// See 'ParseMessageBytes' for parsing with name decompression.

Since Ptr is a sized type, and it implements Copy and Clone, it’s straightforward to handle and move around. However, this depends on the domain name type. It can be changed using Ptr::map_name() and Ptr::map_name_by_ref().

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

To serialize a Ptr in the wire format, use BuildInMessage (which supports name compression). If name compression is not desired, use BuildBytes.

Fields§

§name: N

The referenced domain name.

Implementations§

Source§

impl<N> Ptr<N>

Source

pub fn map_name<R, F: FnOnce(N) -> R>(self, f: F) -> Ptr<R>

Map the domain name within to another type.

Source

pub fn map_name_by_ref<'r, R, F: FnOnce(&'r N) -> R>(&'r self, f: F) -> Ptr<R>

Map a reference to the domain name within to another type.

Trait Implementations§

Source§

impl<N> BuildBytes for Ptr<N>
where N: BuildBytes,

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<N: BuildInMessage> BuildInMessage for Ptr<N>

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<N: CanonicalName> CanonicalRecordData for Ptr<N>

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<N: Clone> Clone for Ptr<N>

Source§

fn clone(&self) -> Ptr<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Copy> Copy for Ptr<N>

Source§

impl<N: Debug> Debug for Ptr<N>

Source§

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

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

impl<N: Eq> Eq for Ptr<N>

Source§

impl<'a, N> From<Ptr<N>> for RecordData<'a, N>

Source§

fn from(value: Ptr<N>) -> Self

Converts to this type from the input type.
Source§

impl<N: Hash> Hash for Ptr<N>

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<N: Ord> Ord for Ptr<N>

Source§

fn cmp(&self, other: &Ptr<N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

impl<'bytes, N> ParseBytes<'bytes> for Ptr<N>
where N: ParseBytes<'bytes>,

Source§

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

Parse a value of Self from the given byte sequence. Read more
Source§

impl<'a, N: ParseMessageBytes<'a>> ParseMessageBytes<'a> for Ptr<N>

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, N: ParseMessageBytes<'a>> ParseRecordData<'a> for Ptr<N>

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, N: ParseBytes<'a>> ParseRecordDataBytes<'a> for Ptr<N>

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<N: PartialEq> PartialEq for Ptr<N>

Source§

fn eq(&self, other: &Ptr<N>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<N: PartialOrd> PartialOrd for Ptr<N>

Source§

fn partial_cmp(&self, other: &Ptr<N>) -> 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<'bytes, N> SplitBytes<'bytes> for Ptr<N>
where N: SplitBytes<'bytes>,

Source§

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

Parse a value of Self from the start of the byte sequence. Read more
Source§

impl<N: PartialEq> StructuralPartialEq for Ptr<N>

Auto Trait Implementations§

§

impl<N> Freeze for Ptr<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for Ptr<N>
where N: RefUnwindSafe,

§

impl<N> Send for Ptr<N>
where N: Send,

§

impl<N> Sync for Ptr<N>
where N: Sync,

§

impl<N> Unpin for Ptr<N>
where N: Unpin,

§

impl<N> UnsafeUnpin for Ptr<N>
where N: UnsafeUnpin,

§

impl<N> UnwindSafe for Ptr<N>
where N: 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<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.
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, 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<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