@@ -113,97 +113,6 @@ impl Scheme {
113113 }
114114}
115115
116- macro_rules! 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_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-
207116impl PartialEq for Scheme {
208117 #[ inline]
209118 fn eq ( & self , other : & Self ) -> bool {
@@ -461,7 +370,7 @@ impl<'a, UserinfoE: Encoder, RegNameE: Encoder> Authority<'a, UserinfoE, RegName
461370
462371 /// Returns the optional [port] subcomponent.
463372 ///
464- /// A scheme may define a [ default port] to use when the port is
373+ /// A scheme may define a default port to use when the port is
465374 /// not present or is empty.
466375 ///
467376 /// Note that the port may be empty, with leading zeros, or larger than [`u16::MAX`].
@@ -470,7 +379,6 @@ impl<'a, UserinfoE: Encoder, RegNameE: Encoder> Authority<'a, UserinfoE, RegName
470379 /// mechanism that allows ports larger than [`u16::MAX`].
471380 ///
472381 /// [port]: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3
473- /// [default port]: Scheme::default_port
474382 ///
475383 /// # Examples
476384 ///
0 commit comments