Skip to main content

DomainLabels

Trait DomainLabels 

pub trait DomainLabels: Sealed {
    type LabelIter<'a>: Iterator<Item = &'a Label> + DoubleEndedIterator + Clone
       where Self: 'a;

    // Required method
    fn labels(&self) -> Self::LabelIter<'_>;

    // Provided methods
    fn label_count(&self) -> usize { ... }
    fn starts_with<D>(&self, prefix: &D) -> bool
       where D: DomainLabels + ?Sized { ... }
    fn ends_with<D>(&self, suffix: &D) -> bool
       where D: DomainLabels + ?Sized { ... }
    fn is_subdomain_of<D>(&self, parent: &D) -> bool
       where D: DomainLabels + ?Sized { ... }
    fn parent(&self) -> Option<Domain> { ... }
    fn suffix_iter(&self) -> SuffixIter<'_, Self> 
       where Self: Sized { ... }
}
Available on crate feature net only.
Expand description

A label-aware view over a domain-like type.

Every method composes purely from labels, so any type that can produce a sequence of Labels in DNS-natural order (most specific label first, TLD last) inherits suffix/subdomain/parent behavior for free.

Required Associated Types§

type LabelIter<'a>: Iterator<Item = &'a Label> + DoubleEndedIterator + Clone where Self: 'a

Iterator over the labels of self, yielded most-specific-first ("www.example.com".labels() yields www, example, com).

Required Methods§

fn labels(&self) -> Self::LabelIter<'_>

Returns an iterator over the labels of self.

Provided Methods§

fn label_count(&self) -> usize

Returns the number of labels.

fn starts_with<D>(&self, prefix: &D) -> bool
where D: DomainLabels + ?Sized,

Returns true if self’s labels start with prefix’s labels (most-specific-end).

Note that starts_with operates on the left edge — the side closest to the leaf. So "www.example.com".starts_with("www") is true.

fn ends_with<D>(&self, suffix: &D) -> bool
where D: DomainLabels + ?Sized,

Returns true if self’s labels end with suffix’s labels (TLD-end).

"www.example.com".ends_with("example.com") is true.

fn is_subdomain_of<D>(&self, parent: &D) -> bool
where D: DomainLabels + ?Sized,

Returns true if self is a subdomain of parent (or equal to it).

Returns false when parent has zero labels (e.g. an IP-valued Host).

fn parent(&self) -> Option<Domain>

Returns the parent Domain (everything but the leftmost label), or None if self has fewer than two labels.

fn suffix_iter(&self) -> SuffixIter<'_, Self>
where Self: Sized,

Iterator over self and each successive parent, ending just before the empty domain. For "a.b.c" yields "a.b.c", "b.c", "c".

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl DomainLabels for Host

§

type LabelIter<'a> = HostLabelIter<'a>

§

impl DomainLabels for Domain