Skip to content

Commit c05bd39

Browse files
PiotrSikoraThomasdezeeuw
authored andcommitted
review: don't map ENOENT to Ok(None).
Signed-off-by: Piotr Sikora <[email protected]>
1 parent 0788a4a commit c05bd39

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/sys/unix.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ impl crate::Socket {
17981798
docsrs,
17991799
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
18001800
)]
1801-
pub fn original_dst(&self) -> io::Result<Option<SockAddr>> {
1801+
pub fn original_dst(&self) -> io::Result<SockAddr> {
18021802
// Safety: `getsockopt` initialises the `SockAddr` for us.
18031803
unsafe {
18041804
SockAddr::try_init(|storage, len| {
@@ -1811,13 +1811,7 @@ impl crate::Socket {
18111811
))
18121812
})
18131813
}
1814-
.map_or_else(
1815-
|e| match e.raw_os_error() {
1816-
Some(libc::ENOENT) => Ok(None),
1817-
_ => Err(e),
1818-
},
1819-
|(_, addr)| Ok(Some(addr)),
1820-
)
1814+
.map(|(_, addr)| addr)
18211815
}
18221816

18231817
/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket.
@@ -1829,7 +1823,7 @@ impl crate::Socket {
18291823
docsrs,
18301824
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
18311825
)]
1832-
pub fn original_dst_ipv6(&self) -> io::Result<Option<SockAddr>> {
1826+
pub fn original_dst_ipv6(&self) -> io::Result<SockAddr> {
18331827
// Safety: `getsockopt` initialises the `SockAddr` for us.
18341828
unsafe {
18351829
SockAddr::try_init(|storage, len| {
@@ -1842,13 +1836,7 @@ impl crate::Socket {
18421836
))
18431837
})
18441838
}
1845-
.map_or_else(
1846-
|e| match e.raw_os_error() {
1847-
Some(libc::ENOENT) => Ok(None),
1848-
_ => Err(e),
1849-
},
1850-
|(_, addr)| Ok(Some(addr)),
1851-
)
1839+
.map(|(_, addr)| addr)
18521840
}
18531841

18541842
/// Copies data between a `file` and this socket using the `sendfile(2)`

0 commit comments

Comments
 (0)