@@ -448,33 +448,17 @@ impl FromPyObject<'_> for UrlHostParts {
448
448
449
449
impl fmt:: Display for UrlHostParts {
450
450
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
451
- let _ = match self {
452
- UrlHostParts {
453
- username : Some ( username) ,
454
- password : None ,
455
- ..
456
- } => write ! ( f, "{username}" ) ,
457
- UrlHostParts {
458
- username : None ,
459
- password : Some ( password) ,
460
- ..
461
- } => write ! ( f, ":{password}" ) ,
462
- UrlHostParts {
463
- username : Some ( username) ,
464
- password : Some ( password) ,
465
- ..
466
- } => write ! ( f, "{username}:{password}" ) ,
467
- UrlHostParts {
468
- username : None ,
469
- password : None ,
470
- ..
471
- } => Ok ( ( ) ) ,
451
+ match ( & self . username , & self . password ) {
452
+ ( Some ( username) , None ) => write ! ( f, "{username}@" ) ?,
453
+ ( None , Some ( password) ) => write ! ( f, ":{password}@" ) ?,
454
+ ( Some ( username) , Some ( password) ) => write ! ( f, "{username}:{password}@" ) ?,
455
+ ( None , None ) => { } ,
472
456
} ;
473
- if self . host . is_some ( ) {
474
- write ! ( f, "@{}" , self . host . as_ref ( ) . unwrap ( ) ) ?;
457
+ if let Some ( host ) = & self . host {
458
+ write ! ( f, "{host}" ) ?;
475
459
}
476
- if self . port . is_some ( ) {
477
- write ! ( f, ":{}" , self . port . as_ref ( ) . unwrap ( ) ) ?;
460
+ if let Some ( port ) = self . port {
461
+ write ! ( f, ":{port}" ) ?;
478
462
}
479
463
Ok ( ( ) )
480
464
}
0 commit comments