Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Common types for the public suffix implementation crates
2 //!
3 //! The types in this crate assume that the input is valid
4 //! UTF-8 encoded domain names. If input is potentially invalid,
5 //! use a higher level crate like the `addr` crate.
6 //!
7 //! Some implentations may also assume that the domain name is
8 //! in lowercase and/or may only support looking up unicode
9 //! domain names.
10
11 #![no_std]
12 #![forbid(unsafe_code)]
13
14 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
15 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#};
16
17 /// A list of all public suffixes
18 pub trait Listrust-analyzer cargo psl-types 2.0.11 List# {
19 /// Finds the suffix information of the given input labels
20 ///
21 /// *NB:* `labels` must be in reverse order
22 fn findrust-analyzer cargo psl-types 2.0.11 List#find().<'a, T>(&self, labels: T) -> Inforust-analyzer cargo psl-types 2.0.11 Info#
23 where
24 T: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a [u8]>;
25
26 /// Get the public suffix of the domain
27 #[inline]
28 fn suffixrust-analyzer cargo psl-types 2.0.11 List#suffix().<'a>(&self, name: &'a [u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'a>> {
29 let mut labels = name.rsplitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]rsplit().(|x| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.');
30 let fqdn = if name.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]ends_with().(b".") {
31 labels.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`RSplit<'a, T, P>`][Iterator]next().();
32 true
33 } else {
34 false
35 };
36 let Inforust-analyzer cargo psl-types 2.0.11 Info# { mut lenrust-analyzer cargo psl-types 2.0.11 Info#len., typrust-analyzer cargo psl-types 2.0.11 Info#typ. } = self.findrust-analyzer cargo psl-types 2.0.11 List#find().(labels);
37 if fqdn {
38 len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
39 }
40 if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
41 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
42 }
43 let offset = name.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().len;
44 let bytes = name.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
45 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Suffixrust-analyzer cargo psl-types 2.0.11 Suffix# { bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes., fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn., typrust-analyzer cargo psl-types 2.0.11 Suffix#typ. })
46 }
47
48 /// Get the registrable domain
49 #[inline]
50 fn domainrust-analyzer cargo psl-types 2.0.11 List#domain().<'a>(&self, name: &'a [u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'a>> {
51 let suffix = self.suffixrust-analyzer cargo psl-types 2.0.11 List#suffix().(name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
52 let name_len = name.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
53 let suffix_len = suffix.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
54 if name_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().suffix_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2 {
55 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
56 }
57 let offset = name_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().suffix_len);
58 let subdomain = name.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
59 let root_label = subdomain.rsplitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]rsplitn().(2, |x| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.').nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`RSplitN<'a, T, P>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
60 let registrable_len = root_label.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().suffix_len;
61 let offset = name_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().registrable_len;
62 let bytes = name.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
63 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Domainrust-analyzer cargo psl-types 2.0.11 Domain# { bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes., suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix. })
64 }
65 }
66
67 impl<L: Listrust-analyzer cargo psl-types 2.0.11 List#> Listrust-analyzer cargo psl-types 2.0.11 List# for &'_ L {
68 #[inline]
69 fn findrust-analyzer cargo psl-types 2.0.11 impl#[`&L`][List]find().<'a, T>(&self, labels: T) -> Inforust-analyzer cargo psl-types 2.0.11 Info#
70 where
71 T: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a [u8]>,
72 {
73 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).findrust-analyzer cargo psl-types 2.0.11 List#find().(labels)
74 }
75 }
76
77 /// Type of suffix
78 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
79 pub enum Typerust-analyzer cargo psl-types 2.0.11 Type# {
80 Icannrust-analyzer cargo psl-types 2.0.11 Type#Icann#,
81 Privaterust-analyzer cargo psl-types 2.0.11 Type#Private#,
82 }
83
84 /// Information about the suffix
85 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
86 pub struct Inforust-analyzer cargo psl-types 2.0.11 Info# {
87 pub lenrust-analyzer cargo psl-types 2.0.11 Info#len.: usize,
88 pub typrust-analyzer cargo psl-types 2.0.11 Info#typ.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Typerust-analyzer cargo psl-types 2.0.11 Type#>,
89 }
90
91 /// The suffix of a domain name
92 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
93 pub struct Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'a> {
94 bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.: &'a [u8],
95 fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn.: bool,
96 typrust-analyzer cargo psl-types 2.0.11 Suffix#typ.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Typerust-analyzer cargo psl-types 2.0.11 Type#>,
97 }
98
99 impl<'a> Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'a> {
100 /// Builds a new suffix
101 #[inline]
102 #[must_use]
103 #[doc(hidden)]
104 pub fn newrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]new().(bytes: &[u8], typ: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Typerust-analyzer cargo psl-types 2.0.11 Type#>) -> Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
105 Suffixrust-analyzer cargo psl-types 2.0.11 Suffix# {
106 bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.,
107 typrust-analyzer cargo psl-types 2.0.11 Suffix#typ.,
108 fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn.: bytes.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]ends_with().(b"."),
109 }
110 }
111
112 /// The suffix as bytes
113 #[inline]
114 #[must_use]
115 pub const fn as_bytesrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]as_bytes().(&self) -> &'a [u8] {
116 self.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.
117 }
118
119 /// Whether or not the suffix is fully qualified (i.e. it ends with a `.`)
120 #[inline]
121 #[must_use]
122 pub const fn is_fqdnrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]is_fqdn().(&self) -> bool {
123 self.fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn.
124 }
125
126 /// Whether this is an `ICANN`, `private` or unknown suffix
127 #[inline]
128 #[must_use]
129 pub const fn typrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]typ().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Typerust-analyzer cargo psl-types 2.0.11 Type#> {
130 self.typrust-analyzer cargo psl-types 2.0.11 Suffix#typ.
131 }
132
133 /// Returns the suffix with a trailing `.` removed
134 #[inline]
135 #[must_use]
136 pub fn trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().(mut self) -> Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`] {
137 if self.fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn. {
138 self.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes. = &self.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#self.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
139 self.fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn. = false;
140 }
141 self
142 }
143
144 /// Whether or not this is a known suffix (i.e. it is explicitly in the public suffix list)
145 // Could be const but Isahc needs support for Rust v1.41
146 #[inline]
147 #[must_use]
148 pub fn is_knownrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]is_known().(&self) -> bool {
149 self.typrust-analyzer cargo psl-types 2.0.11 Suffix#typ..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()
150 }
151 }
152
153 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
154 #[inline]
155 fn eqrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][`PartialEq<Self>`]) -> bool {
156 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.)
157 }
158 }
159
160 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&[u8]> for Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
161 #[inline]
162 fn eqrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][`PartialEq<&[u8]>`]eq().(&self, other: &&[u8]) -> bool {
163 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other)
164 }
165 }
166
167 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&str> for Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
168 #[inline]
169 fn eqrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][`PartialEq<&str>`]eq().(&self, other: &&str) -> bool {
170 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
171 }
172 }
173
174 impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
175 #[inline]
176 fn cmprust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][Ord]cmp().(&self, other: &Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
177 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][Ord]cmp().(strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.))
178 }
179 }
180
181 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
182 #[inline]
183 fn partial_cmprust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
184 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][Ord]cmp().(strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes.)))
185 }
186 }
187
188 impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
189 #[inline]
190 fn hashrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'_>`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
191 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Suffix#bytes..hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[`[T]`][Hash]hash().(state);
192 }
193 }
194
195 /// A registrable domain name
196 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
197 pub struct Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'a> {
198 bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes.: &'a [u8],
199 suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix.: Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'a>,
200 }
201
202 impl<'a> Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'a> {
203 /// Builds a root domain
204 #[inline]
205 #[must_use]
206 #[doc(hidden)]
207 pub const fn newrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]new().(bytes: &'a [u8], suffix: Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'a>) -> Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'a> {
208 Domainrust-analyzer cargo psl-types 2.0.11 Domain# { bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes., suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix. }
209 }
210
211 /// The domain name as bytes
212 #[inline]
213 #[must_use]
214 pub const fn as_bytesrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]as_bytes().(&self) -> &'a [u8] {
215 self.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes.
216 }
217
218 /// The public suffix of this domain name
219 #[inline]
220 #[must_use]
221 pub const fn suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(&self) -> Suffixrust-analyzer cargo psl-types 2.0.11 Suffix#<'_> {
222 self.suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix.
223 }
224
225 /// Returns the domain with a trailing `.` removed
226 #[inline]
227 #[must_use]
228 pub fn trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().(mut self) -> Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`] {
229 if self.suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix..fqdnrust-analyzer cargo psl-types 2.0.11 Suffix#fqdn. {
230 self.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes. = &self.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#self.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
231 self.suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix. = self.suffixrust-analyzer cargo psl-types 2.0.11 Domain#suffix..trimrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]trim().();
232 }
233 self
234 }
235 }
236
237 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'_> {
238 #[inline]
239 fn eqrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][`PartialEq<Self>`]) -> bool {
240 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes.)
241 }
242 }
243
244 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&[u8]> for Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'_> {
245 #[inline]
246 fn eqrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][`PartialEq<&[u8]>`]eq().(&self, other: &&[u8]) -> bool {
247 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other)
248 }
249 }
250
251 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&str> for Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'_> {
252 #[inline]
253 fn eqrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][`PartialEq<&str>`]eq().(&self, other: &&str) -> bool {
254 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
255 }
256 }
257
258 impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'_> {
259 #[inline]
260 fn cmprust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][Ord]cmp().(&self, other: &Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
261 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][Ord]cmp().(strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes.))
262 }
263 }
264
265 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'_> {
266 #[inline]
267 fn partial_cmprust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
268 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][Ord]cmp().(strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(other.bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes.)))
269 }
270 }
271
272 impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for Domainrust-analyzer cargo psl-types 2.0.11 Domain#<'_> {
273 #[inline]
274 fn hashrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'_>`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
275 self.trimrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]trim().().bytesrust-analyzer cargo psl-types 2.0.11 Domain#bytes..hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[`[T]`][Hash]hash().(state);
276 }
277 }
278
279 #[inline]
280 fn strip_dotrust-analyzer cargo psl-types 2.0.11 strip_dot().(bytes: &[u8]) -> &[u8] {
281 if bytes.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]ends_with().(b".") {
282 &bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
283 } else {
284 bytes
285 }
286 }
287
288 #[cfg(test)]
289 mod testrust-analyzer cargo psl-types 2.0.11 test/ {
290 use superrust-analyzer cargo psl-types 2.0.11 crate/::{Inforust-analyzer cargo psl-types 2.0.11 Info#, Listrust-analyzer cargo psl-types 2.0.11 List# as Pslrust-analyzer cargo psl-types 2.0.11 List#};
291
292 struct Listrust-analyzer cargo psl-types 2.0.11 test/List#;
293
294 impl Pslrust-analyzer cargo psl-types 2.0.11 List# for Listrust-analyzer cargo psl-types 2.0.11 test/List# {
295 fn findrust-analyzer cargo psl-types 2.0.11 test/impl#[List][List]find().<'a, T>(&self, mut labels: T) -> Inforust-analyzer cargo psl-types 2.0.11 Info#
296 where
297 T: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a [u8]>,
298 {
299 match labels.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
300 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(label) => Inforust-analyzer cargo psl-types 2.0.11 Info# {
301 lenrust-analyzer cargo psl-types 2.0.11 Info#len.: label.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(),
302 typrust-analyzer cargo psl-types 2.0.11 Info#typ.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
303 },
304 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Inforust-analyzer cargo psl-types 2.0.11 Info# { lenrust-analyzer cargo psl-types 2.0.11 Info#len.: 0, typrust-analyzer cargo psl-types 2.0.11 Info#typ.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# },
305 }
306 }
307 }
308
309 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
310 fn www_example_comrust-analyzer cargo psl-types 2.0.11 test/www_example_com().() {
311 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"www.example.com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
312 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, "example.com");
313 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(), "com");
314 }
315
316 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
317 fn example_comrust-analyzer cargo psl-types 2.0.11 test/example_com().() {
318 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
319 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, "example.com");
320 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(), "com");
321 }
322
323 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
324 fn example_com_rust-analyzer cargo psl-types 2.0.11 test/example_com_().() {
325 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com.").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
326 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, "example.com.");
327 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(), "com.");
328 }
329
330 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
331 fn fqdn_comparisonsrust-analyzer cargo psl-types 2.0.11 test/fqdn_comparisons().() {
332 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com.").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
333 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, "example.com");
334 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(), "com");
335 }
336
337 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
338 fn non_fqdn_comparisonsrust-analyzer cargo psl-types 2.0.11 test/non_fqdn_comparisons().() {
339 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
340 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, "example.com.");
341 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(), "com.");
342 }
343
344 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
345 fn self_comparisonsrust-analyzer cargo psl-types 2.0.11 test/self_comparisons().() {
346 let fqdn = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com.").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
347 let non_fqdn = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
348 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fqdn, non_fqdn);
349 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fqdn.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().(), non_fqdn.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().());
350 }
351
352 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
353 fn btreemap_comparisonsrust-analyzer cargo psl-types 2.0.11 test/btreemap_comparisons().() {
354 extern crate allocrust-analyzer cargo psl-types 2.0.11 test/alloc/;
355 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#;
356
357 let mut domain = BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().();
358 let mut suffix = BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().();
359
360 let fqdn = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com.").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
361 domain.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(fqdn);
362 suffix.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(fqdn.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().());
363
364 let non_fqdn = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
365 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(domain.containsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]contains().(&non_fqdn));
366 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(suffix.containsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]contains().(&non_fqdn.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().()));
367 }
368
369 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
370 fn hashmap_comparisonsrust-analyzer cargo psl-types 2.0.11 test/hashmap_comparisons().() {
371 extern crate stdrust-analyzer cargo psl-types 2.0.11 test/std/;
372 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#;
373
374 let mut domain = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().();
375 let mut suffix = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().();
376
377 let fqdn = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com.").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
378 domain.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(fqdn);
379 suffix.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(fqdn.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().());
380
381 let non_fqdn = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"example.com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("domain name");
382 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(domain.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&non_fqdn));
383 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(suffix.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&non_fqdn.suffixrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]suffix().()));
384 }
385
386 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
387 fn comrust-analyzer cargo psl-types 2.0.11 test/com().() {
388 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"com");
389 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
390
391 let suffix = Listrust-analyzer cargo psl-types 2.0.11 test/List#.suffixrust-analyzer cargo psl-types 2.0.11 List#suffix().(b"com").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("public suffix");
392 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, "com");
393 }
394
395 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
396 fn rootrust-analyzer cargo psl-types 2.0.11 test/root().() {
397 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b".");
398 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
399
400 let suffix = Listrust-analyzer cargo psl-types 2.0.11 test/List#.suffixrust-analyzer cargo psl-types 2.0.11 List#suffix().(b".").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("public suffix");
401 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, ".");
402 }
403
404 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
405 fn empty_stringrust-analyzer cargo psl-types 2.0.11 test/empty_string().() {
406 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(b"");
407 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(domain, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
408
409 let suffix = Listrust-analyzer cargo psl-types 2.0.11 test/List#.suffixrust-analyzer cargo psl-types 2.0.11 List#suffix().(b"");
410 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
411 }
412
413 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
414 #[allow(dead_code)]
415 fn accessors_borrow_correctlyrust-analyzer cargo psl-types 2.0.11 test/accessors_borrow_correctly().() {
416 fn return_suffixrust-analyzer cargo psl-types 2.0.11 test/return_suffix().(domain: &str) -> &[u8] {
417 let suffix = Listrust-analyzer cargo psl-types 2.0.11 test/List#.suffixrust-analyzer cargo psl-types 2.0.11 List#suffix().(domain.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
418 suffix.as_bytesrust-analyzer cargo psl-types 2.0.11 impl#[`Suffix<'a>`]as_bytes().()
419 }
420
421 fn return_domainrust-analyzer cargo psl-types 2.0.11 test/return_domain().(name: &str) -> &[u8] {
422 let domain = Listrust-analyzer cargo psl-types 2.0.11 test/List#.domainrust-analyzer cargo psl-types 2.0.11 List#domain().(name.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
423 domain.as_bytesrust-analyzer cargo psl-types 2.0.11 impl#[`Domain<'a>`]as_bytes().()
424 }
425 }
426 }