mirror of
https://github.com/BurntSushi/walkdir.git
synced 2025-09-28 06:00:32 +00:00
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.
This commit is contained in:
parent
abf3a15887
commit
21be522788
@ -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"
|
||||
|
||||
|
37
src/dent.rs
37
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
11
src/error.rs
11
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(),
|
||||
|
@ -601,7 +601,7 @@ impl Ancestor {
|
||||
#[cfg(windows)]
|
||||
fn new(dent: &DirEntry) -> io::Result<Ancestor> {
|
||||
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<Self, P> {
|
||||
FilterEntry { it: self, predicate: predicate }
|
||||
FilterEntry { it: self, predicate }
|
||||
}
|
||||
|
||||
/// Skips the current directory.
|
||||
|
Loading…
x
Reference in New Issue
Block a user