pub struct Name<'a>(_);
Expand description

A domain name represented as an inverted list of labels.

Implementations

Parse from the specified buff, starting at position pos.

Errors

It will error if the buffer does not contain a valid domain name. If the domain name has been compressed the buffer should include all previous bytes from the DNS packet to be considered valid. Jump pointers should only point backwards inside the buf.

Serialize the Name and append it tho the end of the provided packet

Create a new, empty, domain name.

let name = Name::new();
assert_eq!(name.to_string(), "".to_string())

Obtain the top level domain (TLD) of the provided domain name.

let mut name = Name::try_from("example.com").unwrap();
assert_eq!(name.tld(), Some("com"))

Push a new label to the end of the domain name, as a subdomain of the current one. Empty labels will be ignored.

let mut name = Name::new();
name.push_label("com");
name.push_label("example");
assert_eq!(name.to_string(), "example.com.".to_string())

Get the number of labels in the domain name.

let mut name = Name::try_from("example.com").unwrap();
assert_eq!(2, name.label_count())

Check if sub is a subdomain of the current domain name.

let mut name = Name::try_from("example.com").unwrap();
let mut sub = Name::try_from("subdomain.example.com").unwrap();

assert!(name.is_subdomain(&sub))

Return an iterator over the labels in human order.

let mut name = Name::try_from("subdomain.example.com").unwrap();
let mut human = name.iter_human();

assert_eq!(human.next(), Some("subdomain"));
assert_eq!(human.next(), Some("example"));
assert_eq!(human.next(), Some("com"));

Return an iterator over the labels in hierarchical order.

let mut name = Name::try_from("subdomain.example.com").unwrap();
let mut hierarchy = name.iter_hierarchy();

assert_eq!(hierarchy.next(), Some("com"));
assert_eq!(hierarchy.next(), Some("example"));
assert_eq!(hierarchy.next(), Some("subdomain"));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.