Skip to content

Commit e2da63a

Browse files
authored
Update src/url.rs
1 parent 8727e51 commit e2da63a

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

src/url.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -448,33 +448,17 @@ impl FromPyObject<'_> for UrlHostParts {
448448

449449
impl fmt::Display for UrlHostParts {
450450
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) => {},
472456
};
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}")?;
475459
}
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}")?;
478462
}
479463
Ok(())
480464
}

0 commit comments

Comments
 (0)