summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-24 02:35:39 +0000
committerGitHub <noreply@github.com>2021-03-24 02:35:39 +0000
commit6af11c1e70b02e1af36fdc339238d3a117fd3a94 (patch)
tree1a9f8560addaa3d531cf5835e3b60d2262fc9dfb
parent3f8a66dc69ba3ae4df6a0f3eb879dc30020965bc (diff)
parent49ed986b79e530a1f5e424a04ce732e70077507f (diff)
downloadnix-6af11c1e70b02e1af36fdc339238d3a117fd3a94.zip
Merge #1401
1401: cleanup: remove redundant unwrap in Dir::from_fd r=asomers a=scottlamb Co-authored-by: Scott Lamb <slamb@slamb.org>
-rw-r--r--src/dir.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/dir.rs b/src/dir.rs
index a58af19c..7c35d70f 100644
--- a/src/dir.rs
+++ b/src/dir.rs
@@ -53,14 +53,12 @@ impl Dir {
/// Converts from a file descriptor, closing it on success or failure.
pub fn from_fd(fd: RawFd) -> Result<Self> {
- let d = unsafe { libc::fdopendir(fd) };
- if d.is_null() {
+ let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
let e = Error::last();
unsafe { libc::close(fd) };
- return Err(e);
- };
- // Always guaranteed to be non-null by the previous check
- Ok(Dir(ptr::NonNull::new(d).unwrap()))
+ e
+ })?;
+ Ok(Dir(d))
}
/// Returns an iterator of `Result<Entry>` which rewinds when finished.