From 21be5227882c4a8816a6db8c42189b384713051c Mon Sep 17 00:00:00 2001 From: vsuryamurthy Date: Thu, 16 Mar 2023 13:55:45 +0100 Subject: [PATCH] impl: use shorthand initialization, remove old work-around This switches to using shorthand struct field initialization. It also removes a work-around for an older version of Rust on Windows. Finally, we remove an explicit dependency on winapi, which was required by the aforementioned work-around. However, we do still indirectly depend on winapi via winapi-util. --- Cargo.toml | 4 ---- src/dent.rs | 37 +++++++------------------------------ src/error.rs | 11 ++++------- src/lib.rs | 6 +++--- 4 files changed, 14 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c71c2fe..d78d02a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,6 @@ members = ["walkdir-list"] [dependencies] same-file = "1.0.1" -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3" -features = ["std", "winnt"] - [target.'cfg(windows)'.dependencies.winapi-util] version = "0.1.1" diff --git a/src/dent.rs b/src/dent.rs index a28ed3d..adf54f7 100644 --- a/src/dent.rs +++ b/src/dent.rs @@ -177,18 +177,6 @@ impl DirEntry { } /// Returns true if and only if this entry points to a directory. - /// - /// This works around a bug in Rust's standard library: - /// https://github.com/rust-lang/rust/issues/46484 - #[cfg(windows)] - pub(crate) fn is_dir(&self) -> bool { - use std::os::windows::fs::MetadataExt; - use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY; - self.metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0 - } - - /// Returns true if and only if this entry points to a directory. - #[cfg(not(windows))] pub(crate) fn is_dir(&self) -> bool { self.ty.is_dir() } @@ -205,13 +193,7 @@ impl DirEntry { let md = ent .metadata() .map_err(|err| Error::from_path(depth, path.clone(), err))?; - Ok(DirEntry { - path: path, - ty: ty, - follow_link: false, - depth: depth, - metadata: md, - }) + Ok(DirEntry { path, ty, follow_link: false, depth, metadata: md }) } #[cfg(unix)] @@ -226,9 +208,9 @@ impl DirEntry { .map_err(|err| Error::from_path(depth, ent.path(), err))?; Ok(DirEntry { path: ent.path(), - ty: ty, + ty, follow_link: false, - depth: depth, + depth, ino: ent.ino(), }) } @@ -241,12 +223,7 @@ impl DirEntry { let ty = ent .file_type() .map_err(|err| Error::from_path(depth, ent.path(), err))?; - Ok(DirEntry { - path: ent.path(), - ty: ty, - follow_link: false, - depth: depth, - }) + Ok(DirEntry { path: ent.path(), ty, follow_link: false, depth }) } #[cfg(windows)] @@ -266,7 +243,7 @@ impl DirEntry { path: pb, ty: md.file_type(), follow_link: follow, - depth: depth, + depth, metadata: md, }) } @@ -290,7 +267,7 @@ impl DirEntry { path: pb, ty: md.file_type(), follow_link: follow, - depth: depth, + depth, ino: md.ino(), }) } @@ -312,7 +289,7 @@ impl DirEntry { path: pb, ty: md.file_type(), follow_link: follow, - depth: depth, + depth, }) } } diff --git a/src/error.rs b/src/error.rs index 9e25a07..3342d9b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -164,10 +164,7 @@ impl Error { pb: PathBuf, err: io::Error, ) -> Self { - Error { - depth: depth, - inner: ErrorInner::Io { path: Some(pb), err: err }, - } + Error { depth, inner: ErrorInner::Io { path: Some(pb), err } } } pub(crate) fn from_entry(dent: &DirEntry, err: io::Error) -> Self { @@ -175,13 +172,13 @@ impl Error { depth: dent.depth(), inner: ErrorInner::Io { path: Some(dent.path().to_path_buf()), - err: err, + err, }, } } pub(crate) fn from_io(depth: usize, err: io::Error) -> Self { - Error { depth: depth, inner: ErrorInner::Io { path: None, err: err } } + Error { depth, inner: ErrorInner::Io { path: None, err } } } pub(crate) fn from_loop( @@ -190,7 +187,7 @@ impl Error { child: &Path, ) -> Self { Error { - depth: depth, + depth, inner: ErrorInner::Loop { ancestor: ancestor.to_path_buf(), child: child.to_path_buf(), diff --git a/src/lib.rs b/src/lib.rs index 929c565..4d41515 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -601,7 +601,7 @@ impl Ancestor { #[cfg(windows)] fn new(dent: &DirEntry) -> io::Result { let handle = Handle::from_path(dent.path())?; - Ok(Ancestor { path: dent.path().to_path_buf(), handle: handle }) + Ok(Ancestor { path: dent.path().to_path_buf(), handle }) } /// Create a new ancestor from the given directory path. @@ -811,7 +811,7 @@ impl IntoIter { where P: FnMut(&DirEntry) -> bool, { - FilterEntry { it: self, predicate: predicate } + FilterEntry { it: self, predicate } } fn handle_entry( @@ -1109,7 +1109,7 @@ where /// [`min_depth`]: struct.WalkDir.html#method.min_depth /// [`max_depth`]: struct.WalkDir.html#method.max_depth pub fn filter_entry(self, predicate: P) -> FilterEntry { - FilterEntry { it: self, predicate: predicate } + FilterEntry { it: self, predicate } } /// Skips the current directory.