Debian Codegraph @

src/component.rs

raw symbols SCIP
1 //! URI/IRI components.
2
3 use craterust-analyzer cargo fluent-uri 0.4.1 crate/::{
4 imprust-analyzer cargo fluent-uri 0.4.1 imp/::{AuthMetarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#, HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#},
5 pct_encrust-analyzer cargo fluent-uri 0.4.1 pct_enc/::{
6 encoderrust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/::{IRegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IRegName#, IUserinforust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IUserinfo#, Portrust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/Port#, RegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/RegName#, Userinforust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/Userinfo#},
7 tablerust-analyzer cargo fluent-uri 0.4.1 pct_enc/table/, EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#, Encoderrust-analyzer cargo fluent-uri 0.4.1 pct_enc/Encoder#,
8 },
9 };
10 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/, iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/::ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#};
11 use ref_castrust-analyzer cargo ref-cast 1.0.25 crate/::{ref_cast_customrust-analyzer cargo ref-cast-impl 1.0.25 ref_cast_custom:, RefCastCustomrust-analyzer cargo ref-cast-impl 1.0.25 RefCastCustom:};
12
13 #[cfg(feature = "net")]
14 use craterust-analyzer cargo fluent-uri 0.4.1 crate/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/::{Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#, Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#};
15
16 #[cfg(all(feature = "net", feature = "std"))]
17 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
18 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/,
19 netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/::{SocketAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddr#, ToSocketAddrsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/socket_addr/ToSocketAddrs#},
20 };
21
22 /// An authority component for IRI.
23 pub type IAuthorityrust-analyzer cargo fluent-uri 0.4.1 component/IAuthority#<'a> = Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#<'a, IUserinforust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IUserinfo#, IRegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IRegName#>;
24
25 /// A parsed host component for IRI.
26 pub type IHostrust-analyzer cargo fluent-uri 0.4.1 component/IHost#<'a> = Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#<'a, IRegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IRegName#>;
27
28 /// A [scheme] component.
29 ///
30 /// [scheme]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
31 ///
32 /// # Comparison
33 ///
34 /// `Scheme`s are compared case-insensitively. You should do a case-insensitive
35 /// comparison if the scheme specification allows both letter cases in the scheme name.
36 ///
37 /// # Examples
38 ///
39 /// ```
40 /// use fluent_uri::{component::Scheme, Uri};
41 ///
42 /// const SCHEME_HTTP: &Scheme = Scheme::new_or_panic("http");
43 ///
44 /// let scheme = Uri::parse("HTTP://EXAMPLE.COM/")?.scheme();
45 ///
46 /// // Case-insensitive comparison.
47 /// assert_eq!(scheme, SCHEME_HTTP);
48 /// // Case-sensitive comparison.
49 /// assert_eq!(scheme.as_str(), "HTTP");
50 /// # Ok::<_, fluent_uri::ParseError>(())
51 /// ```
52 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(RefCastCustomrust-analyzer cargo ref-cast-impl 1.0.25 RefCastCustom:)]
53 #[repr(transparent)]
54 pub struct Schemerust-analyzer cargo fluent-uri 0.4.1 component/Scheme# {
55 innerrust-analyzer cargo fluent-uri 0.4.1 component/Scheme#inner.: str,
56 }
57
58 const ASCII_CASE_MASKrust-analyzer cargo fluent-uri 0.4.1 component/ASCII_CASE_MASK.: u8 = 0b0010_0000;
59
60 impl Schemerust-analyzer cargo fluent-uri 0.4.1 component/Scheme# {
61 #[ref_cast_customrust-analyzer cargo ref-cast-impl 1.0.25 ref_cast_custom:]
62 #[inline]
63 pub(craterust-analyzer cargo fluent-uri 0.4.1 crate/) const fn new_validatedrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]new_validated().(scheme: &str) -> &Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme];
64
65 /// Converts a string slice to `&Scheme`.
66 ///
67 /// # Panics
68 ///
69 /// Panics if the string is not a valid scheme name according to
70 /// [Section 3.1 of RFC 3986][scheme]. For a non-panicking variant,
71 /// use [`new`](Self::new).
72 ///
73 /// [scheme]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
74 #[inline]
75 #[must_use]
76 pub const fn new_or_panicrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]new_or_panic().(s: &str) -> &Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme] {
77 match Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]::newrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]new().(s) {
78 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(scheme) => scheme,
79 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("invalid scheme"),
80 }
81 }
82
83 /// Converts a string slice to `&Scheme`, returning `None` if the conversion fails.
84 #[inline]
85 #[must_use]
86 pub const fn newrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]new().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]> {
87 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), [first, rem @ ..]
88 if first.is_ascii_alphabeticrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_alphabetic().() && tablerust-analyzer cargo fluent-uri 0.4.1 pct_enc/table/::SCHEMErust-analyzer cargo fluent-uri 0.4.1 pct_enc/table/SCHEME..validaterust-analyzer cargo fluent-uri 0.4.1 pct_enc/table/impl#[Table]validate().(rem))
89 {
90 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]::new_validatedrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]new_validated().(s))
91 } else {
92 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
93 }
94 }
95
96 /// Returns the scheme component as a string slice.
97 ///
98 /// # Examples
99 ///
100 /// ```
101 /// use fluent_uri::Uri;
102 ///
103 /// let uri = Uri::parse("http://example.com/")?;
104 /// assert_eq!(uri.scheme().as_str(), "http");
105 /// let uri = Uri::parse("HTTP://EXAMPLE.COM/")?;
106 /// assert_eq!(uri.scheme().as_str(), "HTTP");
107 /// # Ok::<_, fluent_uri::ParseError>(())
108 /// ```
109 #[inline]
110 #[must_use]
111 pub fn as_strrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme]as_str().(&self) -> &str {
112 &self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Scheme#inner.
113 }
114 }
115
116 macro_rules! default_portrust-analyzer cargo fluent-uri 0.4.1 component/default_port! {
117 ($($name:literal, $bname:literal => $port:literal, rfc($rfc:literal))*) => {
118 impl Scheme {
119 /// Returns the optional default port of the scheme if it is
120 /// registered [at IANA][iana] with a permanent status.
121 ///
122 /// [iana]: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
123 ///
124 /// The following table lists all schemes concerned, their default ports, and references:
125 ///
126 /// | Scheme | Port | Reference |
127 /// | - | - | - |
128 $(#[doc = concat!("| ", $name, " | ", $port, " | [RFC ", $rfc, "](https://datatracker.ietf.org/doc/html/rfc", $rfc, ") |")])*
129 #[must_use]
130 pub fn default_port(&self) -> Option<u16> {
131 const MAX_LEN: usize = {
132 let mut res = 0;
133 $(
134 if $name.len() > res {
135 res = $name.len();
136 }
137 )*
138 res
139 };
140
141 let len = self.inner.len();
142 if len > MAX_LEN {
143 return None;
144 }
145
146 let mut buf = [0; MAX_LEN];
147 for (i, b) in self.inner.bytes().enumerate() {
148 buf[i] = b | ASCII_CASE_MASK;
149 }
150
151 match &buf[..len] {
152 $($bname => Some($port),)*
153 _ => None,
154 }
155 }
156 }
157 };
158 }
159
160 default_portrust-analyzer cargo fluent-uri 0.4.1 component/default_port!! {
161 "aaa", b"aaa" => 3868, rfc(6733)
162 "aaas", b"aaas" => 5658, rfc(6733)
163 "acap", b"acap" => 674, rfc(2244)
164 "cap", b"cap" => 1026, rfc(4324)
165 "coap", b"coap" => 5683, rfc(7252)
166 "coap+tcp", b"coap+tcp" => 5683, rfc(8323)
167 "coap+ws", b"coap+ws" => 80, rfc(8323)
168 "coaps", b"coaps" => 5684, rfc(7252)
169 "coaps+tcp", b"coaps+tcp" => 5684, rfc(8323)
170 "coaps+ws", b"coaps+ws" => 443, rfc(8323)
171 "dict", b"dict" => 2628, rfc(2229)
172 "dns", b"dns" => 53, rfc(4501)
173 "ftp", b"ftp" => 21, rfc(1738)
174 "go", b"go" => 1096, rfc(3368)
175 "gopher", b"gopher" => 70, rfc(4266)
176 "http", b"http" => 80, rfc(9110)
177 "https", b"https" => 443, rfc(9110)
178 "icap", b"icap" => 1344, rfc(3507)
179 "imap", b"imap" => 143, rfc(5092)
180 "ipp", b"ipp" => 631, rfc(3510)
181 "ipps", b"ipps" => 631, rfc(7472)
182 "ldap", b"ldap" => 389, rfc(4516)
183 "mtqp", b"mtqp" => 1038, rfc(3887)
184 "mupdate", b"mupdate" => 3905, rfc(3656)
185 "nfs", b"nfs" => 2049, rfc(2224)
186 "nntp", b"nntp" => 119, rfc(5538)
187 "pop", b"pop" => 110, rfc(2384)
188 "rtsp", b"rtsp" => 554, rfc(7826)
189 "rtsps", b"rtsps" => 322, rfc(7826)
190 "rtspu", b"rtspu" => 554, rfc(2326)
191 "snmp", b"snmp" => 161, rfc(4088)
192 "stun", b"stun" => 3478, rfc(7064)
193 "stuns", b"stuns" => 5349, rfc(7064)
194 "telnet", b"telnet" => 23, rfc(4248)
195 "tip", b"tip" => 3372, rfc(2371)
196 "tn3270", b"tn3270" => 23, rfc(6270)
197 "turn", b"turn" => 3478, rfc(7065)
198 "turns", b"turns" => 5349, rfc(7065)
199 "vemmi", b"vemmi" => 575, rfc(2122)
200 "vnc", b"vnc" => 5900, rfc(7869)
201 "ws", b"ws" => 80, rfc(6455)
202 "wss", b"wss" => 443, rfc(6455)
203 "z39.50r", b"z39.50r" => 210, rfc(2056)
204 "z39.50s", b"z39.50s" => 210, rfc(2056)
205 }
206
207 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for Schemerust-analyzer cargo fluent-uri 0.4.1 component/Scheme# {
208 #[inline]
209 fn eqrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme][`PartialEq<Self>`]) -> bool {
210 let (a, b) = (self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Scheme#inner..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), other.innerrust-analyzer cargo fluent-uri 0.4.1 component/Scheme#inner..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
211 // The only characters allowed in a scheme are alphabets, digits, '+', '-' and '.'.
212 // Their ASCII codes allow us to simply set the sixth bits and compare.
213 a.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 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().b.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()
214 && iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/zip/zip().(a, b).allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|(x, y)| x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitOr<u8>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitOr<u8>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitOr<u8>`]bitor().ASCII_CASE_MASKrust-analyzer cargo fluent-uri 0.4.1 component/ASCII_CASE_MASK. 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().y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitOr<u8>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitOr<u8>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitOr<u8>`]bitor().ASCII_CASE_MASKrust-analyzer cargo fluent-uri 0.4.1 component/ASCII_CASE_MASK.)
215 }
216 }
217
218 impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for Schemerust-analyzer cargo fluent-uri 0.4.1 component/Scheme# {}
219
220 impl 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# for Schemerust-analyzer cargo fluent-uri 0.4.1 component/Scheme# {
221 fn hashrust-analyzer cargo fluent-uri 0.4.1 component/impl#[Scheme][Hash]hash().<H: hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
222 let mut buf = [0; 8];
223 for chunk in self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Scheme#inner..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().chunksrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks().(8) {
224 let len = chunk.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
225 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len {
226 buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = chunk[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]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/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().ASCII_CASE_MASKrust-analyzer cargo fluent-uri 0.4.1 component/ASCII_CASE_MASK.;
227 }
228 state.writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().);
229 }
230 }
231 }
232
233 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
234 struct AuthorityInnerrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#<'a> {
235 valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val.: &'a str,
236 metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta.: AuthMetarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#,
237 }
238
239 impl<'a> AuthorityInnerrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#<'a> {
240 fn userinforust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]userinfo().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#<IUserinforust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IUserinfo#>> {
241 let host_start = self.metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_boundsrust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_bounds..0;
242 (host_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0).thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#::new_validatedrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]new_validated().(&self.valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val.[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#host_start 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().))
243 }
244
245 fn hostrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]host().(&self) -> &'a str {
246 let (start, end) = self.metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_boundsrust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_bounds.;
247 &self.valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
248 }
249
250 fn portrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]port().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#<Portrust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/Port#>> {
251 let host_end = self.metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_boundsrust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_bounds..1;
252 (host_end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().self.valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()).thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#::new_validatedrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]new_validated().(&self.valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().host_end 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/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().))
253 }
254
255 fn port_to_u16rust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]port_to_u16().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16>, ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#> {
256 self.portrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]port().()
257 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|s| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]is_empty().())
258 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.as_strrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]as_str().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().())
259 .transposerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<Result<T, E>>`]transpose().()
260 }
261
262 #[cfg(all(feature = "net", feature = "std"))]
263 fn socket_addrsrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]socket_addrs().(&self, default_port: u16) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<impl 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# = SocketAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddr#>> {
264 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/;
265
266 let port = self
267 .port_to_u16rust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]port_to_u16().()
268 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, "invalid port value"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
269 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(default_port);
270
271 match self.metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_metarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_meta. {
272 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::Ipv4rust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#Ipv4#(addr) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(addr, port).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()].into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()),
273 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::Ipv6rust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#Ipv6#(addr) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(addr, port).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()].into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()),
274 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::IpvFuturerust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#IpvFuture# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
275 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#,
276 "address mechanism not supported",
277 )),
278 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::RegNamerust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#RegName# => {
279 let name = EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#::<IRegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/IRegName#>::new_validatedrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]new_validated().(self.hostrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]host().());
280 let name = name.decoderust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]decode().().to_stringrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`Decode<'a>`]to_string().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
281 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
282 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#,
283 "registered name does not decode to valid UTF-8",
284 )
285 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
286 (&name[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/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., port).to_socket_addrsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/socket_addr/impl#[`(&str, u16)`][ToSocketAddrs]to_socket_addrs().()
287 }
288 }
289 }
290 }
291
292 /// An [authority] component.
293 ///
294 /// [authority]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2
295 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
296 pub struct Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#<'a, UserinfoE = Userinforust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/Userinfo#, RegNameE = RegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/RegName#> {
297 innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner.: AuthorityInnerrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#<'a>,
298 _markerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#_marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<(UserinfoE, RegNameE)>,
299 }
300
301 impl<'a, T, U> Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#<'a, T, U> {
302 pub(craterust-analyzer cargo fluent-uri 0.4.1 crate/) fn castrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, T, U>`]cast().<V, W>(self) -> Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#<'a, V, W> {
303 Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority# {
304 innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner.: self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner.,
305 _markerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#_marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
306 }
307 }
308 }
309
310 impl<'a, UserinfoE: Encoderrust-analyzer cargo fluent-uri 0.4.1 pct_enc/Encoder#, RegNameE: Encoderrust-analyzer cargo fluent-uri 0.4.1 pct_enc/Encoder#> Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#<'a, UserinfoE, RegNameE> {
311 pub(craterust-analyzer cargo fluent-uri 0.4.1 crate/) const fn newrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]new().(val: &'a str, meta: AuthMetarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#) -> Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`] {
312 Selfrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`] {
313 innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner.: AuthorityInnerrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner# { valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val., metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta. },
314 _markerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#_marker.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
315 }
316 }
317
318 /// An empty authority component.
319 pub const EMPTYrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]EMPTY.: Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#<'static, UserinfoE, RegNameE> = Authorityrust-analyzer cargo fluent-uri 0.4.1 component/Authority#::newrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]new().("", AuthMetarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#::EMPTYrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[AuthMeta]EMPTY.);
320
321 #[cfg(feature = "alloc")]
322 pub(craterust-analyzer cargo fluent-uri 0.4.1 crate/) fn metarust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]meta().(&self) -> AuthMetarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta# {
323 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta.
324 }
325
326 /// Returns the authority component as a string slice.
327 ///
328 /// # Examples
329 ///
330 /// ```
331 /// use fluent_uri::Uri;
332 ///
333 /// let uri = Uri::parse("http://[email protected]:8080/")?;
334 /// let auth = uri.authority().unwrap();
335 /// assert_eq!(auth.as_str(), "[email protected]:8080");
336 /// # Ok::<_, fluent_uri::ParseError>(())
337 /// ```
338 #[inline]
339 #[must_use]
340 pub fn as_strrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]as_str().(&self) -> &'a str {
341 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val.
342 }
343
344 /// Returns the optional [userinfo] subcomponent.
345 ///
346 /// [userinfo]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1
347 ///
348 /// # Examples
349 ///
350 /// ```
351 /// use fluent_uri::{pct_enc::EStr, Uri};
352 ///
353 /// let uri = Uri::parse("http://[email protected]/")?;
354 /// let auth = uri.authority().unwrap();
355 /// assert_eq!(auth.userinfo(), Some(EStr::new_or_panic("user")));
356 ///
357 /// let uri = Uri::parse("http://example.com/")?;
358 /// let auth = uri.authority().unwrap();
359 /// assert_eq!(auth.userinfo(), None);
360 /// # Ok::<_, fluent_uri::ParseError>(())
361 /// ```
362 #[must_use]
363 pub fn userinforust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]userinfo().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#<UserinfoE>> {
364 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..userinforust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]userinfo().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#::castrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]cast().)
365 }
366
367 /// Returns the [host] subcomponent as a string slice.
368 ///
369 /// The host subcomponent is always present, although it may be empty.
370 ///
371 /// The square brackets enclosing an IPv6 or IPvFuture address are included.
372 ///
373 /// Note that ASCII characters within a host are *case-insensitive*.
374 ///
375 /// [host]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
376 ///
377 /// # Examples
378 ///
379 /// ```
380 /// use fluent_uri::Uri;
381 ///
382 /// let uri = Uri::parse("http://[email protected]:8080/")?;
383 /// let auth = uri.authority().unwrap();
384 /// assert_eq!(auth.host(), "example.com");
385 ///
386 /// let uri = Uri::parse("file:///path/to/file")?;
387 /// let auth = uri.authority().unwrap();
388 /// assert_eq!(auth.host(), "");
389 ///
390 /// let uri = Uri::parse("http://[::1]")?;
391 /// let auth = uri.authority().unwrap();
392 /// assert_eq!(auth.host(), "[::1]");
393 /// # Ok::<_, fluent_uri::ParseError>(())
394 /// ```
395 #[must_use]
396 pub fn hostrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]host().(&self) -> &'a str {
397 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..hostrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]host().()
398 }
399
400 /// Returns the parsed [host] subcomponent.
401 ///
402 /// Note that ASCII characters within a host are *case-insensitive*.
403 ///
404 /// [host]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
405 ///
406 /// # Examples
407 ///
408 /// ```
409 /// use fluent_uri::{component::Host, pct_enc::EStr, Uri};
410 #[cfg_attr(feature = "net", doc = "use std::net::{Ipv4Addr, Ipv6Addr};")]
411 ///
412 /// let uri = Uri::parse("foo://127.0.0.1")?;
413 /// let auth = uri.authority().unwrap();
414 #[cfg_attr(
415 feature = "net",
416 doc = "assert!(matches!(auth.host_parsed(), Host::Ipv4(Ipv4Addr::LOCALHOST)));"
417 )]
418 #[cfg_attr(
419 not(feature = "net"),
420 doc = "assert!(matches!(auth.host_parsed(), Host::Ipv4 { .. }));"
421 )]
422 ///
423 /// let uri = Uri::parse("foo://[::1]")?;
424 /// let auth = uri.authority().unwrap();
425 #[cfg_attr(
426 feature = "net",
427 doc = "assert!(matches!(auth.host_parsed(), Host::Ipv6(Ipv6Addr::LOCALHOST)));"
428 )]
429 #[cfg_attr(
430 not(feature = "net"),
431 doc = "assert!(matches!(auth.host_parsed(), Host::Ipv6 { .. }));"
432 )]
433 ///
434 /// let uri = Uri::parse("foo://[v1.addr]")?;
435 /// let auth = uri.authority().unwrap();
436 /// // The API design for IPvFuture addresses is to be determined.
437 /// assert!(matches!(auth.host_parsed(), Host::IpvFuture { .. }));
438 ///
439 /// let uri = Uri::parse("foo://localhost")?;
440 /// let auth = uri.authority().unwrap();
441 /// assert!(matches!(auth.host_parsed(), Host::RegName(name) if name == "localhost"));
442 /// # Ok::<_, fluent_uri::ParseError>(())
443 /// ```
444 #[must_use]
445 pub fn host_parsedrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]host_parsed().(&self) -> Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#<'a, RegNameE> {
446 match self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_metarust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_meta. {
447 #[cfg(feature = "net")]
448 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::Ipv4rust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#Ipv4#(addr) => Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#::Ipv4rust-analyzer cargo fluent-uri 0.4.1 component/Host#Ipv4#(addr),
449 #[cfg(feature = "net")]
450 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::Ipv6rust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#Ipv6#(addr) => Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#::Ipv6rust-analyzer cargo fluent-uri 0.4.1 component/Host#Ipv6#(addr),
451
452 #[cfg(not(feature = "net"))]
453 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::Ipv4rust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#Ipv4#() => Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#::Ipv4rust-analyzer cargo fluent-uri 0.4.1 component/Host#Ipv4#(),
454 #[cfg(not(feature = "net"))]
455 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::Ipv6rust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#Ipv6#() => Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#::Ipv6rust-analyzer cargo fluent-uri 0.4.1 component/Host#Ipv6#(),
456
457 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::IpvFuturerust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#IpvFuture# => Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#::IpvFuturerust-analyzer cargo fluent-uri 0.4.1 component/Host#IpvFuture#,
458 HostMetarust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#::RegNamerust-analyzer cargo fluent-uri 0.4.1 imp/HostMeta#RegName# => Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#::RegNamerust-analyzer cargo fluent-uri 0.4.1 component/Host#RegName#(EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#::new_validatedrust-analyzer cargo fluent-uri 0.4.1 pct_enc/impl#[`EStr<E>`]new_validated().(self.hostrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]host().())),
459 }
460 }
461
462 /// Returns the optional [port] subcomponent.
463 ///
464 /// A scheme may define a [default port] to use when the port is
465 /// not present or is empty.
466 ///
467 /// Note that the port may be empty, with leading zeros, or larger than [`u16::MAX`].
468 /// It is up to you to decide whether to deny such ports, fallback to the scheme's
469 /// default if it is empty, ignore the leading zeros, or use a special addressing
470 /// mechanism that allows ports larger than [`u16::MAX`].
471 ///
472 /// [port]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3
473 /// [default port]: Scheme::default_port
474 ///
475 /// # Examples
476 ///
477 /// ```
478 /// use fluent_uri::{pct_enc::EStr, Uri};
479 ///
480 /// let uri = Uri::parse("foo://localhost:4673/")?;
481 /// let auth = uri.authority().unwrap();
482 /// assert_eq!(auth.port(), Some(EStr::new_or_panic("4673")));
483 ///
484 /// let uri = Uri::parse("foo://localhost:/")?;
485 /// let auth = uri.authority().unwrap();
486 /// assert_eq!(auth.port(), Some(EStr::EMPTY));
487 ///
488 /// let uri = Uri::parse("foo://localhost/")?;
489 /// let auth = uri.authority().unwrap();
490 /// assert_eq!(auth.port(), None);
491 ///
492 /// let uri = Uri::parse("foo://localhost:123456/")?;
493 /// let auth = uri.authority().unwrap();
494 /// assert_eq!(auth.port(), Some(EStr::new_or_panic("123456")));
495 /// # Ok::<_, fluent_uri::ParseError>(())
496 /// ```
497 #[must_use]
498 pub fn portrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]port().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#<Portrust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/Port#>> {
499 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..portrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]port().()
500 }
501
502 /// Converts the [port] subcomponent to `u16`, if present and nonempty.
503 ///
504 /// Returns `Ok(None)` if the port is not present or is empty. Leading zeros are ignored.
505 ///
506 /// [port]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3
507 ///
508 /// # Errors
509 ///
510 /// Returns `Err` if the port cannot be parsed into `u16`.
511 ///
512 /// # Examples
513 ///
514 /// ```
515 /// use fluent_uri::Uri;
516 ///
517 /// let uri = Uri::parse("foo://localhost:4673/")?;
518 /// let auth = uri.authority().unwrap();
519 /// assert_eq!(auth.port_to_u16(), Ok(Some(4673)));
520 ///
521 /// let uri = Uri::parse("foo://localhost/")?;
522 /// let auth = uri.authority().unwrap();
523 /// assert_eq!(auth.port_to_u16(), Ok(None));
524 ///
525 /// let uri = Uri::parse("foo://localhost:/")?;
526 /// let auth = uri.authority().unwrap();
527 /// assert_eq!(auth.port_to_u16(), Ok(None));
528 ///
529 /// let uri = Uri::parse("foo://localhost:123456/")?;
530 /// let auth = uri.authority().unwrap();
531 /// assert!(auth.port_to_u16().is_err());
532 /// # Ok::<_, fluent_uri::ParseError>(())
533 /// ```
534 pub fn port_to_u16rust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]port_to_u16().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16>, ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#> {
535 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..port_to_u16rust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]port_to_u16().()
536 }
537
538 /// Converts the host and the port subcomponent to an iterator of resolved [`SocketAddr`]s.
539 ///
540 /// The default port is used if the port component is not present or is empty.
541 /// A registered name is first [decoded] and then resolved with [`ToSocketAddrs`].
542 /// Punycode encoding is **not** performed prior to resolution.
543 ///
544 /// [decoded]: EStr::decode
545 ///
546 /// # Errors
547 ///
548 /// Returns `Err` if any of the following is true.
549 ///
550 /// - The port cannot be parsed into `u16`.
551 /// - The host is an IPvFuture address.
552 /// - A registered name does not decode to valid UTF-8 or fails to resolve.
553 #[cfg(all(feature = "net", feature = "std"))]
554 pub fn socket_addrsrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]socket_addrs().(&self, default_port: u16) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<impl 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# = SocketAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddr#>> {
555 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..socket_addrsrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`AuthorityInner<'a>`]socket_addrs().(default_port)
556 }
557
558 /// Checks whether a userinfo subcomponent is present.
559 ///
560 /// # Examples
561 ///
562 /// ```
563 /// use fluent_uri::Uri;
564 ///
565 /// let uri = Uri::parse("http://[email protected]/")?;
566 /// assert!(uri.authority().unwrap().has_userinfo());
567 ///
568 /// let uri = Uri::parse("http://example.com/")?;
569 /// assert!(!uri.authority().unwrap().has_userinfo());
570 /// # Ok::<_, fluent_uri::ParseError>(())
571 #[inline]
572 #[must_use]
573 pub fn has_userinforust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]has_userinfo().(&self) -> bool {
574 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_boundsrust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_bounds..0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0
575 }
576
577 /// Checks whether a port subcomponent is present.
578 ///
579 /// # Examples
580 ///
581 /// ```
582 /// use fluent_uri::Uri;
583 ///
584 /// let uri = Uri::parse("foo://localhost:4673/")?;
585 /// assert!(uri.authority().unwrap().has_port());
586 ///
587 /// // The port subcomponent can be empty.
588 /// let uri = Uri::parse("foo://localhost:/")?;
589 /// assert!(uri.authority().unwrap().has_port());
590 ///
591 /// let uri = Uri::parse("foo://localhost/")?;
592 /// let auth = uri.authority().unwrap();
593 /// assert!(!uri.authority().unwrap().has_port());
594 /// # Ok::<_, fluent_uri::ParseError>(())
595 /// ```
596 #[inline]
597 #[must_use]
598 pub fn has_portrust-analyzer cargo fluent-uri 0.4.1 component/impl#[`Authority<'a, UserinfoE, RegNameE>`]has_port().(&self) -> bool {
599 self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..metarust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#meta..host_boundsrust-analyzer cargo fluent-uri 0.4.1 imp/AuthMeta#host_bounds..1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().self.innerrust-analyzer cargo fluent-uri 0.4.1 component/Authority#inner..valrust-analyzer cargo fluent-uri 0.4.1 component/AuthorityInner#val..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()
600 }
601 }
602
603 /// A parsed [host] component.
604 ///
605 /// [host]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
606 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
607 #[cfg_attr(fuzzing, derive(PartialEq, Eq))]
608 pub enum Hostrust-analyzer cargo fluent-uri 0.4.1 component/Host#<'a, RegNameE: Encoderrust-analyzer cargo fluent-uri 0.4.1 pct_enc/Encoder# = RegNamerust-analyzer cargo fluent-uri 0.4.1 pct_enc/encoder/RegName#> {
609 /// An IPv4 address.
610 #[cfg_attr(not(feature = "net"), non_exhaustive)]
611 Ipv4rust-analyzer cargo fluent-uri 0.4.1 component/Host#Ipv4#(
612 /// The address.
613 #[cfg(feature = "net")]
614 Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#,
615 ),
616 /// An IPv6 address.
617 #[cfg_attr(not(feature = "net"), non_exhaustive)]
618 Ipv6rust-analyzer cargo fluent-uri 0.4.1 component/Host#Ipv6#(
619 /// The address.
620 #[cfg(feature = "net")]
621 Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#,
622 ),
623 /// An IP address of future version.
624 ///
625 /// This variant is marked as non-exhaustive because the API design
626 /// for IPvFuture addresses is to be determined.
627 #[non_exhaustive]
628 IpvFuturerust-analyzer cargo fluent-uri 0.4.1 component/Host#IpvFuture#,
629 /// A registered name.
630 ///
631 /// Note that ASCII characters within a registered name are *case-insensitive*.
632 RegNamerust-analyzer cargo fluent-uri 0.4.1 component/Host#RegName#(&'a EStrrust-analyzer cargo fluent-uri 0.4.1 pct_enc/EStr#<RegNameE>),
633 }