Skip to content

Commit

Permalink
Use map_or_else
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Jan 10, 2025
1 parent cec1d1c commit 628e08d
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/app/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,35 @@ impl Display for DebugInfo {
gio::NetworkConnectivity::Full => "Full".into(),
other => format!("Other {other:?}").into(),
};
let pings = self
.ping_results
.iter()
.map(|(d, r)| match r {
DevicePingResult::ResolveFailed(error) => {
format!("Host {}\n Failed to resolve: {error}", d.host())
}
DevicePingResult::Pinged(addresses) => {
format!(
"Host {}:\n{}",
d.host(),
addresses
.iter()
.map(|(addr, result)| {
format!(
" {addr}: {}",
result
.as_ref()
.map(|d| format!("{}ms", d.as_millis()))
.unwrap_or_else(ToString::to_string)
)
})
.collect::<Vec<_>>()
.join("\n")
)
}
})
.collect::<Vec<_>>()
.join("\n");
let pings =
self.ping_results
.iter()
.map(|(d, r)| match r {
DevicePingResult::ResolveFailed(error) => {
format!("Host {}\n Failed to resolve: {error}", d.host())
}
DevicePingResult::Pinged(addresses) => {
format!(
"Host {}:\n{}",
d.host(),
addresses
.iter()
.map(|(addr, result)| {
format!(
" {addr}: {}",
result.as_ref().map_or_else(
ToString::to_string,
|d| format!("{}ms", d.as_millis())
)
)
})
.collect::<Vec<_>>()
.join("\n")
)
}
})
.collect::<Vec<_>>()
.join("\n");
let arp_cache_contents = match &self.arp_cache_contents {
Ok(contents) => Cow::Borrowed(contents),
Err(error) => Cow::Owned(format!("Failed: {error}")),
Expand Down

0 comments on commit 628e08d

Please sign in to comment.