@@ -70,10 +70,10 @@ pub enum HostType {
7070impl From < c_uint > for HostType {
7171 fn from ( value : c_uint ) -> Self {
7272 match value {
73- 0 => HostType :: Domain ,
74- 1 => HostType :: IPV4 ,
75- 2 => HostType :: IPV6 ,
76- _ => HostType :: Domain ,
73+ 0 => Self :: Domain ,
74+ 1 => Self :: IPV4 ,
75+ 2 => Self :: IPV6 ,
76+ _ => Self :: Domain ,
7777 }
7878 }
7979}
@@ -93,14 +93,14 @@ pub enum SchemeType {
9393impl From < c_uint > for SchemeType {
9494 fn from ( value : c_uint ) -> Self {
9595 match value {
96- 0 => SchemeType :: Http ,
97- 1 => SchemeType :: NotSpecial ,
98- 2 => SchemeType :: Https ,
99- 3 => SchemeType :: Ws ,
100- 4 => SchemeType :: Ftp ,
101- 5 => SchemeType :: Wss ,
102- 6 => SchemeType :: File ,
103- _ => SchemeType :: NotSpecial ,
96+ 0 => Self :: Http ,
97+ 1 => Self :: NotSpecial ,
98+ 2 => Self :: Https ,
99+ 3 => Self :: Ws ,
100+ 4 => Self :: Ftp ,
101+ 5 => Self :: Wss ,
102+ 6 => Self :: File ,
103+ _ => Self :: NotSpecial ,
104104 }
105105 }
106106}
@@ -187,7 +187,7 @@ impl std::error::Error for SetterError {}
187187type SetterResult = Result < ( ) , SetterError > ;
188188
189189#[ inline]
190- fn setter_result ( successful : bool ) -> SetterResult {
190+ const fn setter_result ( successful : bool ) -> SetterResult {
191191 if successful {
192192 Ok ( ( ) )
193193 } else {
@@ -204,7 +204,7 @@ impl Url {
204204 /// .expect("This is a valid URL. Should have parsed it.");
205205 /// assert_eq!(out.protocol(), "https:");
206206 /// ```
207- pub fn parse < Input > ( input : Input , base : Option < & str > ) -> Result < Url , ParseUrlError < Input > >
207+ pub fn parse < Input > ( input : Input , base : Option < & str > ) -> Result < Self , ParseUrlError < Input > >
208208 where
209209 Input : AsRef < str > ,
210210 {
@@ -236,6 +236,7 @@ impl Url {
236236 /// assert!(Url::can_parse("https://ada-url.github.io/ada", None));
237237 /// assert!(Url::can_parse("/pathname", Some("https://ada-url.github.io/ada")));
238238 /// ```
239+ #[ must_use]
239240 pub fn can_parse ( input : & str , base : Option < & str > ) -> bool {
240241 unsafe {
241242 if let Some ( base) = base {
@@ -252,11 +253,13 @@ impl Url {
252253 }
253254
254255 /// Returns the type of the host such as default, ipv4 or ipv6.
256+ #[ must_use]
255257 pub fn host_type ( & self ) -> HostType {
256258 HostType :: from ( unsafe { ffi:: ada_get_host_type ( self . 0 ) } )
257259 }
258260
259261 /// Returns the type of the scheme such as http, https, etc.
262+ #[ must_use]
260263 pub fn scheme_type ( & self ) -> SchemeType {
261264 SchemeType :: from ( unsafe { ffi:: ada_get_scheme_type ( self . 0 ) } )
262265 }
@@ -271,6 +274,7 @@ impl Url {
271274 /// let url = Url::parse("blob:https://example.com/foo", None).expect("Invalid URL");
272275 /// assert_eq!(url.origin(), "https://example.com");
273276 /// ```
277+ #[ must_use]
274278 pub fn origin ( & self ) -> & str {
275279 unsafe {
276280 let out = ffi:: ada_get_origin ( self . 0 ) ;
@@ -282,6 +286,7 @@ impl Url {
282286 /// Return the parsed version of the URL with all components.
283287 ///
284288 /// For more information, read [WHATWG URL spec](https://url.spec.whatwg.org/#dom-url-href)
289+ #[ must_use]
285290 pub fn href ( & self ) -> & str {
286291 unsafe { ffi:: ada_get_href ( self . 0 ) } . as_str ( )
287292 }
@@ -309,6 +314,7 @@ impl Url {
309314 /// let url = Url::parse("ftp://rms:secret123@example.com", None).expect("Invalid URL");
310315 /// assert_eq!(url.username(), "rms");
311316 /// ```
317+ #[ must_use]
312318 pub fn username ( & self ) -> & str {
313319 unsafe { ffi:: ada_get_username ( self . 0 ) } . as_str ( )
314320 }
@@ -327,7 +333,7 @@ impl Url {
327333 ffi:: ada_set_username (
328334 self . 0 ,
329335 input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
330- input. map_or ( 0 , |i| i . len ( ) ) ,
336+ input. map_or ( 0 , str :: len) ,
331337 )
332338 } )
333339 }
@@ -342,6 +348,7 @@ impl Url {
342348 /// let url = Url::parse("ftp://rms:secret123@example.com", None).expect("Invalid URL");
343349 /// assert_eq!(url.password(), "secret123");
344350 /// ```
351+ #[ must_use]
345352 pub fn password ( & self ) -> & str {
346353 unsafe { ffi:: ada_get_password ( self . 0 ) } . as_str ( )
347354 }
@@ -360,7 +367,7 @@ impl Url {
360367 ffi:: ada_set_password (
361368 self . 0 ,
362369 input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
363- input. map_or ( 0 , |i| i . len ( ) ) ,
370+ input. map_or ( 0 , str :: len) ,
364371 )
365372 } )
366373 }
@@ -378,6 +385,7 @@ impl Url {
378385 /// let url = Url::parse("https://example.com:8080", None).expect("Invalid URL");
379386 /// assert_eq!(url.port(), "8080");
380387 /// ```
388+ #[ must_use]
381389 pub fn port ( & self ) -> & str {
382390 unsafe { ffi:: ada_get_port ( self . 0 ) } . as_str ( )
383391 }
@@ -392,14 +400,11 @@ impl Url {
392400 /// assert_eq!(url.href(), "https://yagiz.co:8080/");
393401 /// ```
394402 pub fn set_port ( & mut self , input : Option < & str > ) -> SetterResult {
395- match input {
396- Some ( value) => setter_result ( unsafe {
397- ffi:: ada_set_port ( self . 0 , value. as_ptr ( ) . cast ( ) , value. len ( ) )
398- } ) ,
399- None => {
400- unsafe { ffi:: ada_clear_port ( self . 0 ) }
401- Ok ( ( ) )
402- }
403+ if let Some ( value) = input {
404+ setter_result ( unsafe { ffi:: ada_set_port ( self . 0 , value. as_ptr ( ) . cast ( ) , value. len ( ) ) } )
405+ } else {
406+ unsafe { ffi:: ada_clear_port ( self . 0 ) }
407+ Ok ( ( ) )
403408 }
404409 }
405410
@@ -420,6 +425,7 @@ impl Url {
420425 /// assert_eq!(url.hash(), "#row=4");
421426 /// assert!(url.has_hash());
422427 /// ```
428+ #[ must_use]
423429 pub fn hash ( & self ) -> & str {
424430 unsafe { ffi:: ada_get_hash ( self . 0 ) } . as_str ( )
425431 }
@@ -450,6 +456,7 @@ impl Url {
450456 /// let url = Url::parse("https://127.0.0.1:8080/index.html", None).expect("Invalid URL");
451457 /// assert_eq!(url.host(), "127.0.0.1:8080");
452458 /// ```
459+ #[ must_use]
453460 pub fn host ( & self ) -> & str {
454461 unsafe { ffi:: ada_get_host ( self . 0 ) } . as_str ( )
455462 }
@@ -468,7 +475,7 @@ impl Url {
468475 ffi:: ada_set_host (
469476 self . 0 ,
470477 input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
471- input. map_or ( 0 , |i| i . len ( ) ) ,
478+ input. map_or ( 0 , str :: len) ,
472479 )
473480 } )
474481 }
@@ -487,6 +494,7 @@ impl Url {
487494 /// let url = Url::parse("https://127.0.0.1:8080/index.html", None).expect("Invalid URL");
488495 /// assert_eq!(url.hostname(), "127.0.0.1");
489496 /// ```
497+ #[ must_use]
490498 pub fn hostname ( & self ) -> & str {
491499 unsafe { ffi:: ada_get_hostname ( self . 0 ) } . as_str ( )
492500 }
@@ -505,7 +513,7 @@ impl Url {
505513 ffi:: ada_set_hostname (
506514 self . 0 ,
507515 input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
508- input. map_or ( 0 , |i| i . len ( ) ) ,
516+ input. map_or ( 0 , str :: len) ,
509517 )
510518 } )
511519 }
@@ -520,6 +528,7 @@ impl Url {
520528 /// let url = Url::parse("https://example.com/api/versions?page=2", None).expect("Invalid URL");
521529 /// assert_eq!(url.pathname(), "/api/versions");
522530 /// ```
531+ #[ must_use]
523532 pub fn pathname ( & self ) -> & str {
524533 unsafe { ffi:: ada_get_pathname ( self . 0 ) } . as_str ( )
525534 }
@@ -538,7 +547,7 @@ impl Url {
538547 ffi:: ada_set_pathname (
539548 self . 0 ,
540549 input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
541- input. map_or ( 0 , |i| i . len ( ) ) ,
550+ input. map_or ( 0 , str :: len) ,
542551 )
543552 } )
544553 }
@@ -556,6 +565,7 @@ impl Url {
556565 /// let url = Url::parse("https://example.com/products", None).expect("Invalid URL");
557566 /// assert_eq!(url.search(), "");
558567 /// ```
568+ #[ must_use]
559569 pub fn search ( & self ) -> & str {
560570 unsafe { ffi:: ada_get_search ( self . 0 ) } . as_str ( )
561571 }
@@ -572,7 +582,7 @@ impl Url {
572582 pub fn set_search ( & mut self , input : Option < & str > ) {
573583 match input {
574584 Some ( value) => unsafe {
575- ffi:: ada_set_search ( self . 0 , value. as_ptr ( ) . cast ( ) , value. len ( ) )
585+ ffi:: ada_set_search ( self . 0 , value. as_ptr ( ) . cast ( ) , value. len ( ) ) ;
576586 } ,
577587 None => unsafe { ffi:: ada_clear_search ( self . 0 ) } ,
578588 }
@@ -588,6 +598,7 @@ impl Url {
588598 /// let url = Url::parse("file:///tmp/foo", None).expect("Invalid URL");
589599 /// assert_eq!(url.protocol(), "file:");
590600 /// ```
601+ #[ must_use]
591602 pub fn protocol ( & self ) -> & str {
592603 unsafe { ffi:: ada_get_protocol ( self . 0 ) } . as_str ( )
593604 }
@@ -606,58 +617,69 @@ impl Url {
606617 }
607618
608619 /// A URL includes credentials if its username or password is not the empty string.
620+ #[ must_use]
609621 pub fn has_credentials ( & self ) -> bool {
610622 unsafe { ffi:: ada_has_credentials ( self . 0 ) }
611623 }
612624
613625 /// Returns true if it has an host but it is the empty string.
626+ #[ must_use]
614627 pub fn has_empty_hostname ( & self ) -> bool {
615628 unsafe { ffi:: ada_has_empty_hostname ( self . 0 ) }
616629 }
617630
618631 /// Returns true if it has a host (included an empty host)
632+ #[ must_use]
619633 pub fn has_hostname ( & self ) -> bool {
620634 unsafe { ffi:: ada_has_hostname ( self . 0 ) }
621635 }
622636
623637 /// Returns true if URL has a non-empty username.
638+ #[ must_use]
624639 pub fn has_non_empty_username ( & self ) -> bool {
625640 unsafe { ffi:: ada_has_non_empty_username ( self . 0 ) }
626641 }
627642
628643 /// Returns true if URL has a non-empty password.
644+ #[ must_use]
629645 pub fn has_non_empty_password ( & self ) -> bool {
630646 unsafe { ffi:: ada_has_non_empty_password ( self . 0 ) }
631647 }
632648
633649 /// Returns true if URL has a port.
650+ #[ must_use]
634651 pub fn has_port ( & self ) -> bool {
635652 unsafe { ffi:: ada_has_port ( self . 0 ) }
636653 }
637654
638655 /// Returns true if URL has password.
656+ #[ must_use]
639657 pub fn has_password ( & self ) -> bool {
640658 unsafe { ffi:: ada_has_password ( self . 0 ) }
641659 }
642660
643661 /// Returns true if URL has a hash/fragment.
662+ #[ must_use]
644663 pub fn has_hash ( & self ) -> bool {
645664 unsafe { ffi:: ada_has_hash ( self . 0 ) }
646665 }
647666
648667 /// Returns true if URL has search/query.
668+ #[ must_use]
649669 pub fn has_search ( & self ) -> bool {
650670 unsafe { ffi:: ada_has_search ( self . 0 ) }
651671 }
652672
653673 /// Returns the parsed version of the URL with all components.
654674 ///
655675 /// For more information, read [WHATWG URL spec](https://url.spec.whatwg.org/#dom-url-href)
676+ #[ must_use]
656677 pub fn as_str ( & self ) -> & str {
657678 self . href ( )
658679 }
659680
660681 /// Returns the URL components of the instance.
682+ #[ must_use]
661683 pub fn components ( & self ) -> UrlComponents {
662684 unsafe { ffi:: ada_get_components ( self . 0 ) . as_ref ( ) . unwrap ( ) } . into ( )
663685 }
@@ -739,7 +761,7 @@ impl Ord for Url {
739761
740762impl hash:: Hash for Url {
741763 fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
742- self . href ( ) . hash ( state)
764+ self . href ( ) . hash ( state) ;
743765 }
744766}
745767
0 commit comments