Skip to content

Commit c2051a8

Browse files
committed
Refactor match statement to map_err
1 parent d0f798b commit c2051a8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

talpid-wireguard/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1046,17 +1046,17 @@ async fn auto_mtu_detection(
10461046
size
10471047
});
10481048

1049-
let first_ping_size = match ping_stream
1049+
let first_ping_size = ping_stream
10501050
.next()
10511051
.await
10521052
.expect("At least one pings should be sent")
1053-
{
1054-
Ok(size) => size,
1055-
// If the first ping we get back timed out, then all of them did
1056-
Err(SurgeError::Timeout { .. }) => return Err(Error::MtuDetectionAllDropped),
1057-
// Short circuit and return error on unexpected error types
1058-
Err(e) => return Err(Error::MtuDetectionPingError(e)),
1059-
};
1053+
// Short-circuit and return on error
1054+
.map_err(|e| match e {
1055+
// If the first ping we get back timed out, then all of them did
1056+
SurgeError::Timeout { .. } => Error::MtuDetectionAllDropped,
1057+
// Unexpected error type
1058+
e => Error::MtuDetectionPingError(e),
1059+
})?;
10601060

10611061
ping_stream
10621062
.timeout(PING_OFFSET_TIMEOUT) // Start a new, sorter, timeout

0 commit comments

Comments
 (0)