Struct fqdn::FQDN

source ·
pub struct FQDN(/* private fields */);
Expand description

A FQDN string.

The inner byte sequence is conformed with the RFC-1035: each label of the FQDN is prefixed by a length byte and the sequence is nul-terminated.

For instance, the FQDN github.com. is exactly represented as b"\x06github\x03com\x00".

FQDN is to &Fqdn as String is to &str: the former in each pair are owned data; the latter are borrowed references.

Methods from Deref<Target = Fqdn>§

source

pub fn is_root(&self) -> bool

Checks if this is the top domain.

The human-readable representation of the top domain is the single dot ..

source

pub fn is_tld(&self) -> bool

Checks if this is a top level domain (TLD).

A TLD is the last part of a FQDN, so this test is equivalent to check is the depth of this FQDN equals 1.

§Example
assert![ ! fqdn!("github.com.").is_tld() ];
assert![ fqdn!("com").is_tld() ];
source

pub fn is_subdomain_of(&self, parent: &Fqdn) -> bool

Checks if this domain is an descendant of another one.

§Example
assert![ fqdn!("github.com.").is_subdomain_of(&fqdn!("github.com.")) ];
assert![ fqdn!("www.rust-lang.github.com").is_subdomain_of(&fqdn!("github.com.")) ];

assert![ ! fqdn!("github.com.").is_subdomain_of(&fqdn!("www.rust-lang.github.com")) ];
source

pub fn tld(&self) -> Option<&Fqdn>

Gets the top level domain.

The TLD is the last part of a FQDN. For instance, the TLD of rust-lang.github.io. is io.

If the FQDN is already a TLD, self is returned. If the FQDN is the top domain, None is returned.

§Example
assert_eq![ fqdn!("rust-lang.github.com.").tld(), Some(fqdn!("com.").as_ref()) ];
assert_eq![ fqdn!(".").tld(), None ];
source

pub fn parent(&self) -> Option<&Fqdn>

Extracts a Fqdn slice with contains the immediate parent domain.

The parent is the domain after remaining the first label. If it is already the top domain, then None is returned.

To iterate over the hierarchy of a FQDN, consider Self::hierarchy

§Example
assert_eq![ fqdn!("github.com").parent(), Some(fqdn!("com").as_ref()) ];
assert_eq![ fqdn!("github.com").parent().unwrap().parent(), None ];
assert_eq![ fqdn!(".").parent(), None ];
source

pub fn hierarchy(&self) -> impl '_ + Iterator<Item = &Fqdn>

Iterates over the parents of the FQDN.

§Example
let fqdn = fqdn!("rust-lang.github.com.");
let mut iter = fqdn.hierarchy();
assert_eq![ iter.next(), Some(fqdn!("rust-lang.github.com.").as_ref()) ];
assert_eq![ iter.next(), Some(fqdn!("github.com.").as_ref()) ];
assert_eq![ iter.next(), Some(fqdn!("com.").as_ref()) ];
assert_eq![ iter.next(), None ];
source

pub fn depth(&self) -> usize

Computes the depth of this domain (i.e. counts the labels)

§Example
assert_eq![ fqdn!("rust-lang.github.com.").depth(), 3 ];
assert_eq![ fqdn!("github.com.").depth(), 2 ];
assert_eq![ fqdn!(".").depth(), 0 ];
source

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

Returns the complete byte sequence of the FQDN.

The returned sequence is terminated by the nul byte.

§Example
assert_eq![ fqdn!("crates.io.").as_bytes(),  b"\x06crates\x02io\x00" ];
source

pub fn as_c_str(&self) -> &CStr

Returns the FQDN as a C string.

source

pub fn labels(&self) -> impl '_ + Iterator<Item = &str>

Iterates over the labels which constitutes the FQDN.

§Example
let fqdn = fqdn!("rust-lang.github.com.");
let mut iter = fqdn.labels();
assert_eq![ iter.next(), Some("rust-lang") ];
assert_eq![ iter.next(), Some("github") ];
assert_eq![ iter.next(), Some("com") ];
assert_eq![ iter.next(), None ];

Trait Implementations§

source§

impl AsRef<Fqdn> for FQDN

source§

fn as_ref(&self) -> &Fqdn

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

impl Borrow<Fqdn> for FQDN

source§

fn borrow(&self) -> &Fqdn

Immutably borrows from an owned value. Read more
source§

impl Clone for FQDN

source§

fn clone(&self) -> FQDN

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 Debug for FQDN

source§

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

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

impl Default for FQDN

source§

fn default() -> FQDN

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

impl Deref for FQDN

§

type Target = Fqdn

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Display for FQDN

source§

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

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

impl From<&Fqdn> for FQDN

source§

fn from(s: &Fqdn) -> FQDN

Converts to this type from the input type.
source§

impl FromStr for FQDN

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for FQDN

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 Ord for FQDN

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 PartialEq<FQDN> for Fqdn

source§

fn eq(&self, other: &FQDN) -> 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 PartialEq<Fqdn> for FQDN

source§

fn eq(&self, other: &Fqdn) -> 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 PartialEq for FQDN

source§

fn eq(&self, other: &Self) -> 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 PartialOrd<FQDN> for Fqdn

source§

fn partial_cmp(&self, other: &FQDN) -> 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 PartialOrd<Fqdn> for FQDN

source§

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

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

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

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

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

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

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

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

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

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

impl PartialOrd for FQDN

source§

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

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

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

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

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

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

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

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

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

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

impl TryInto<FQDN> for CString

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<FQDN, Self::Error>

Performs the conversion.
source§

impl TryInto<FQDN> for Vec<u8>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<FQDN, Self::Error>

Performs the conversion.
source§

impl Eq for FQDN

Auto Trait Implementations§

§

impl Freeze for FQDN

§

impl RefUnwindSafe for FQDN

§

impl Send for FQDN

§

impl Sync for FQDN

§

impl Unpin for FQDN

§

impl UnwindSafe for FQDN

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, 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<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.