@@ -70,10 +70,10 @@ pub enum HostType {
70
70
impl From < c_uint > for HostType {
71
71
fn from ( value : c_uint ) -> Self {
72
72
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 ,
77
77
}
78
78
}
79
79
}
@@ -93,14 +93,14 @@ pub enum SchemeType {
93
93
impl From < c_uint > for SchemeType {
94
94
fn from ( value : c_uint ) -> Self {
95
95
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 ,
104
104
}
105
105
}
106
106
}
@@ -187,7 +187,7 @@ impl std::error::Error for SetterError {}
187
187
type SetterResult = Result < ( ) , SetterError > ;
188
188
189
189
#[ inline]
190
- fn setter_result ( successful : bool ) -> SetterResult {
190
+ const fn setter_result ( successful : bool ) -> SetterResult {
191
191
if successful {
192
192
Ok ( ( ) )
193
193
} else {
@@ -204,7 +204,7 @@ impl Url {
204
204
/// .expect("This is a valid URL. Should have parsed it.");
205
205
/// assert_eq!(out.protocol(), "https:");
206
206
/// ```
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 > >
208
208
where
209
209
Input : AsRef < str > ,
210
210
{
@@ -236,6 +236,7 @@ impl Url {
236
236
/// assert!(Url::can_parse("https://ada-url.github.io/ada", None));
237
237
/// assert!(Url::can_parse("/pathname", Some("https://ada-url.github.io/ada")));
238
238
/// ```
239
+ #[ must_use]
239
240
pub fn can_parse ( input : & str , base : Option < & str > ) -> bool {
240
241
unsafe {
241
242
if let Some ( base) = base {
@@ -252,11 +253,13 @@ impl Url {
252
253
}
253
254
254
255
/// Returns the type of the host such as default, ipv4 or ipv6.
256
+ #[ must_use]
255
257
pub fn host_type ( & self ) -> HostType {
256
258
HostType :: from ( unsafe { ffi:: ada_get_host_type ( self . 0 ) } )
257
259
}
258
260
259
261
/// Returns the type of the scheme such as http, https, etc.
262
+ #[ must_use]
260
263
pub fn scheme_type ( & self ) -> SchemeType {
261
264
SchemeType :: from ( unsafe { ffi:: ada_get_scheme_type ( self . 0 ) } )
262
265
}
@@ -271,6 +274,7 @@ impl Url {
271
274
/// let url = Url::parse("blob:https://example.com/foo", None).expect("Invalid URL");
272
275
/// assert_eq!(url.origin(), "https://example.com");
273
276
/// ```
277
+ #[ must_use]
274
278
pub fn origin ( & self ) -> & str {
275
279
unsafe {
276
280
let out = ffi:: ada_get_origin ( self . 0 ) ;
@@ -282,6 +286,7 @@ impl Url {
282
286
/// Return the parsed version of the URL with all components.
283
287
///
284
288
/// For more information, read [WHATWG URL spec](https://url.spec.whatwg.org/#dom-url-href)
289
+ #[ must_use]
285
290
pub fn href ( & self ) -> & str {
286
291
unsafe { ffi:: ada_get_href ( self . 0 ) } . as_str ( )
287
292
}
@@ -309,6 +314,7 @@ impl Url {
309
314
/// let url = Url::parse("ftp://rms:[email protected] ", None).expect("Invalid URL");
310
315
/// assert_eq!(url.username(), "rms");
311
316
/// ```
317
+ #[ must_use]
312
318
pub fn username ( & self ) -> & str {
313
319
unsafe { ffi:: ada_get_username ( self . 0 ) } . as_str ( )
314
320
}
@@ -327,7 +333,7 @@ impl Url {
327
333
ffi:: ada_set_username (
328
334
self . 0 ,
329
335
input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
330
- input. map_or ( 0 , |i| i . len ( ) ) ,
336
+ input. map_or ( 0 , str :: len) ,
331
337
)
332
338
} )
333
339
}
@@ -342,6 +348,7 @@ impl Url {
342
348
/// let url = Url::parse("ftp://rms:[email protected] ", None).expect("Invalid URL");
343
349
/// assert_eq!(url.password(), "secret123");
344
350
/// ```
351
+ #[ must_use]
345
352
pub fn password ( & self ) -> & str {
346
353
unsafe { ffi:: ada_get_password ( self . 0 ) } . as_str ( )
347
354
}
@@ -360,7 +367,7 @@ impl Url {
360
367
ffi:: ada_set_password (
361
368
self . 0 ,
362
369
input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
363
- input. map_or ( 0 , |i| i . len ( ) ) ,
370
+ input. map_or ( 0 , str :: len) ,
364
371
)
365
372
} )
366
373
}
@@ -378,6 +385,7 @@ impl Url {
378
385
/// let url = Url::parse("https://example.com:8080", None).expect("Invalid URL");
379
386
/// assert_eq!(url.port(), "8080");
380
387
/// ```
388
+ #[ must_use]
381
389
pub fn port ( & self ) -> & str {
382
390
unsafe { ffi:: ada_get_port ( self . 0 ) } . as_str ( )
383
391
}
@@ -392,14 +400,11 @@ impl Url {
392
400
/// assert_eq!(url.href(), "https://yagiz.co:8080/");
393
401
/// ```
394
402
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 ( ( ) )
403
408
}
404
409
}
405
410
@@ -420,6 +425,7 @@ impl Url {
420
425
/// assert_eq!(url.hash(), "#row=4");
421
426
/// assert!(url.has_hash());
422
427
/// ```
428
+ #[ must_use]
423
429
pub fn hash ( & self ) -> & str {
424
430
unsafe { ffi:: ada_get_hash ( self . 0 ) } . as_str ( )
425
431
}
@@ -450,6 +456,7 @@ impl Url {
450
456
/// let url = Url::parse("https://127.0.0.1:8080/index.html", None).expect("Invalid URL");
451
457
/// assert_eq!(url.host(), "127.0.0.1:8080");
452
458
/// ```
459
+ #[ must_use]
453
460
pub fn host ( & self ) -> & str {
454
461
unsafe { ffi:: ada_get_host ( self . 0 ) } . as_str ( )
455
462
}
@@ -468,7 +475,7 @@ impl Url {
468
475
ffi:: ada_set_host (
469
476
self . 0 ,
470
477
input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
471
- input. map_or ( 0 , |i| i . len ( ) ) ,
478
+ input. map_or ( 0 , str :: len) ,
472
479
)
473
480
} )
474
481
}
@@ -487,6 +494,7 @@ impl Url {
487
494
/// let url = Url::parse("https://127.0.0.1:8080/index.html", None).expect("Invalid URL");
488
495
/// assert_eq!(url.hostname(), "127.0.0.1");
489
496
/// ```
497
+ #[ must_use]
490
498
pub fn hostname ( & self ) -> & str {
491
499
unsafe { ffi:: ada_get_hostname ( self . 0 ) } . as_str ( )
492
500
}
@@ -505,7 +513,7 @@ impl Url {
505
513
ffi:: ada_set_hostname (
506
514
self . 0 ,
507
515
input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
508
- input. map_or ( 0 , |i| i . len ( ) ) ,
516
+ input. map_or ( 0 , str :: len) ,
509
517
)
510
518
} )
511
519
}
@@ -520,6 +528,7 @@ impl Url {
520
528
/// let url = Url::parse("https://example.com/api/versions?page=2", None).expect("Invalid URL");
521
529
/// assert_eq!(url.pathname(), "/api/versions");
522
530
/// ```
531
+ #[ must_use]
523
532
pub fn pathname ( & self ) -> & str {
524
533
unsafe { ffi:: ada_get_pathname ( self . 0 ) } . as_str ( )
525
534
}
@@ -538,7 +547,7 @@ impl Url {
538
547
ffi:: ada_set_pathname (
539
548
self . 0 ,
540
549
input. unwrap_or ( "" ) . as_ptr ( ) . cast ( ) ,
541
- input. map_or ( 0 , |i| i . len ( ) ) ,
550
+ input. map_or ( 0 , str :: len) ,
542
551
)
543
552
} )
544
553
}
@@ -556,6 +565,7 @@ impl Url {
556
565
/// let url = Url::parse("https://example.com/products", None).expect("Invalid URL");
557
566
/// assert_eq!(url.search(), "");
558
567
/// ```
568
+ #[ must_use]
559
569
pub fn search ( & self ) -> & str {
560
570
unsafe { ffi:: ada_get_search ( self . 0 ) } . as_str ( )
561
571
}
@@ -572,7 +582,7 @@ impl Url {
572
582
pub fn set_search ( & mut self , input : Option < & str > ) {
573
583
match input {
574
584
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 ( ) ) ;
576
586
} ,
577
587
None => unsafe { ffi:: ada_clear_search ( self . 0 ) } ,
578
588
}
@@ -588,6 +598,7 @@ impl Url {
588
598
/// let url = Url::parse("file:///tmp/foo", None).expect("Invalid URL");
589
599
/// assert_eq!(url.protocol(), "file:");
590
600
/// ```
601
+ #[ must_use]
591
602
pub fn protocol ( & self ) -> & str {
592
603
unsafe { ffi:: ada_get_protocol ( self . 0 ) } . as_str ( )
593
604
}
@@ -606,58 +617,69 @@ impl Url {
606
617
}
607
618
608
619
/// A URL includes credentials if its username or password is not the empty string.
620
+ #[ must_use]
609
621
pub fn has_credentials ( & self ) -> bool {
610
622
unsafe { ffi:: ada_has_credentials ( self . 0 ) }
611
623
}
612
624
613
625
/// Returns true if it has an host but it is the empty string.
626
+ #[ must_use]
614
627
pub fn has_empty_hostname ( & self ) -> bool {
615
628
unsafe { ffi:: ada_has_empty_hostname ( self . 0 ) }
616
629
}
617
630
618
631
/// Returns true if it has a host (included an empty host)
632
+ #[ must_use]
619
633
pub fn has_hostname ( & self ) -> bool {
620
634
unsafe { ffi:: ada_has_hostname ( self . 0 ) }
621
635
}
622
636
623
637
/// Returns true if URL has a non-empty username.
638
+ #[ must_use]
624
639
pub fn has_non_empty_username ( & self ) -> bool {
625
640
unsafe { ffi:: ada_has_non_empty_username ( self . 0 ) }
626
641
}
627
642
628
643
/// Returns true if URL has a non-empty password.
644
+ #[ must_use]
629
645
pub fn has_non_empty_password ( & self ) -> bool {
630
646
unsafe { ffi:: ada_has_non_empty_password ( self . 0 ) }
631
647
}
632
648
633
649
/// Returns true if URL has a port.
650
+ #[ must_use]
634
651
pub fn has_port ( & self ) -> bool {
635
652
unsafe { ffi:: ada_has_port ( self . 0 ) }
636
653
}
637
654
638
655
/// Returns true if URL has password.
656
+ #[ must_use]
639
657
pub fn has_password ( & self ) -> bool {
640
658
unsafe { ffi:: ada_has_password ( self . 0 ) }
641
659
}
642
660
643
661
/// Returns true if URL has a hash/fragment.
662
+ #[ must_use]
644
663
pub fn has_hash ( & self ) -> bool {
645
664
unsafe { ffi:: ada_has_hash ( self . 0 ) }
646
665
}
647
666
648
667
/// Returns true if URL has search/query.
668
+ #[ must_use]
649
669
pub fn has_search ( & self ) -> bool {
650
670
unsafe { ffi:: ada_has_search ( self . 0 ) }
651
671
}
652
672
653
673
/// Returns the parsed version of the URL with all components.
654
674
///
655
675
/// For more information, read [WHATWG URL spec](https://url.spec.whatwg.org/#dom-url-href)
676
+ #[ must_use]
656
677
pub fn as_str ( & self ) -> & str {
657
678
self . href ( )
658
679
}
659
680
660
681
/// Returns the URL components of the instance.
682
+ #[ must_use]
661
683
pub fn components ( & self ) -> UrlComponents {
662
684
unsafe { ffi:: ada_get_components ( self . 0 ) . as_ref ( ) . unwrap ( ) } . into ( )
663
685
}
@@ -739,7 +761,7 @@ impl Ord for Url {
739
761
740
762
impl hash:: Hash for Url {
741
763
fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
742
- self . href ( ) . hash ( state)
764
+ self . href ( ) . hash ( state) ;
743
765
}
744
766
}
745
767
0 commit comments