simple_dns

Struct Name

Source
pub struct Name<'a> { /* private fields */ }
Expand description

A Name represents a domain-name, which consists of character strings separated by dots.
Each section of a name is called label
ex: google.com consists of two labels google and com

A valid name contains only alphanumeric characters, hyphen (-), underscore (_) or dots (.) and must not exceed 255 characters. Each label must not exceed 63 characters.

Microsoft implementation allows unicode characters in the name content. To create a name with unicode characters, use Name::new_unchecked or Name::new_with_labels

Implementations§

Source§

impl<'a> Name<'a>

Source

pub fn new(name: &'a str) -> Result<Self>

Creates a new Name. Returns Result::<Name>::Ok if given name contents are valid.

Source

pub fn new_unchecked(name: &'a str) -> Self

Create a new Name without checking for size limits or contents

Source

pub fn new_with_labels(labels: &[Label<'a>]) -> Self

Creates a new Name with given labels

Allows construction of labels with . in them.

Verify if name ends with .local.

Source

pub fn iter(&'a self) -> Iter<'_, Label<'a>>

Returns an Iter of this Name Labels

Source

pub fn is_subdomain_of(&self, other: &Name<'_>) -> bool

Returns true if self is a subdomain of other

Source

pub fn without(&self, domain: &Name<'_>) -> Option<Name<'_>>

Returns the subdomain part of self, based on domain. If self is not a subdomain of domain, returns None

Example:

let name = Name::new_unchecked("sub.domain.local");
let domain = Name::new_unchecked("domain.local");

assert!(domain.without(&name).is_none());

let sub = name.without(&domain).unwrap();
assert_eq!(sub.to_string(), "sub")
Source

pub fn into_owned<'b>(self) -> Name<'b>

Transforms the inner data into its owned type

Source

pub fn get_labels(&self) -> &[Label<'_>]

Get the labels that compose this name

Trait Implementations§

Source§

impl<'a> Clone for Name<'a>

Source§

fn clone(&self) -> Name<'a>

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<'a> Debug for Name<'a>

Source§

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

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

impl<'a> Display for Name<'a>

Source§

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

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

impl<'a> From<&'a [Label<'a>]> for Name<'a>

Source§

fn from(labels: &'a [Label<'a>]) -> Self

Converts to this type from the input type.
Source§

impl<'a, const N: usize> From<[Label<'a>; N]> for Name<'a>

Source§

fn from(labels: [Label<'a>; N]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for CNAME<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for MB<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for MD<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for MF<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for MG<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for MR<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for NS<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for NSAP_PTR<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for PTR<'a>

Source§

fn from(value: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for Name<'a>

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<'a> PartialEq for Name<'a>

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<'a> TryFrom<&'a str> for Name<'a>

Source§

type Error = SimpleDnsError

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

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> Eq for Name<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Name<'a>

§

impl<'a> RefUnwindSafe for Name<'a>

§

impl<'a> Send for Name<'a>

§

impl<'a> Sync for Name<'a>

§

impl<'a> Unpin for Name<'a>

§

impl<'a> UnwindSafe for Name<'a>

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 u8)

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

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

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.