Skip to content

Commit 24d081a

Browse files
committed
feat: add fs::read_dir::DirEntry with precompose_unicode support.
It's available with the `fs-read-dir` feature toggle.
1 parent 7d8d167 commit 24d081a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

gix-features/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ progress-unit-bytes = ["dep:bytesize", "prodash?/unit-bytes"]
2727
## If set, walkdir iterators will be multi-threaded.
2828
fs-walkdir-parallel = [ "dep:jwalk", "dep:gix-utils" ]
2929

30+
## Provide utilities suitable for working with the `std::fs::read_dir()`.
31+
fs-read-dir = ["dep:gix-utils"]
32+
3033
## Implement `tracing` with `tracing-core`, which provides applications with valuable performance details if they opt-in to it.
3134
##
3235
## Note that this may have overhead as well, thus instrumentations should be used stategically, only providing coarse tracing by default and adding details

gix-features/src/fs.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod shared {
2121
}
2222
}
2323

24-
#[cfg(any(feature = "walkdir", feature = "fs-walkdir-parallel"))]
24+
#[cfg(any(feature = "walkdir", feature = "fs-walkdir-parallel", feature = "fs-read-dir"))]
2525
mod walkdir_precompose {
2626
use std::borrow::Cow;
2727
use std::ffi::OsStr;
@@ -83,11 +83,13 @@ mod walkdir_precompose {
8383

8484
/// A platform over entries in a directory, which may or may not precompose unicode after retrieving
8585
/// paths from the file system.
86+
#[cfg(any(feature = "walkdir", feature = "fs-walkdir-parallel"))]
8687
pub struct WalkDir<T> {
8788
pub(crate) inner: Option<T>,
8889
pub(crate) precompose_unicode: bool,
8990
}
9091

92+
#[cfg(any(feature = "walkdir", feature = "fs-walkdir-parallel"))]
9193
pub struct WalkDirIter<T, I, E>
9294
where
9395
T: Iterator<Item = Result<I, E>>,
@@ -97,6 +99,7 @@ mod walkdir_precompose {
9799
pub(crate) precompose_unicode: bool,
98100
}
99101

102+
#[cfg(any(feature = "walkdir", feature = "fs-walkdir-parallel"))]
100103
impl<T, I, E> Iterator for WalkDirIter<T, I, E>
101104
where
102105
T: Iterator<Item = Result<I, E>>,
@@ -112,6 +115,32 @@ mod walkdir_precompose {
112115
}
113116
}
114117

118+
///
119+
#[cfg(feature = "fs-read-dir")]
120+
pub mod read_dir {
121+
use std::borrow::Cow;
122+
use std::ffi::OsStr;
123+
use std::fs::FileType;
124+
use std::path::Path;
125+
126+
/// A directory entry adding precompose-unicode support to [`std::fs::DirEntry`].
127+
pub type DirEntry = super::walkdir_precompose::DirEntry<std::fs::DirEntry>;
128+
129+
impl super::walkdir_precompose::DirEntryApi for std::fs::DirEntry {
130+
fn path(&self) -> Cow<'_, Path> {
131+
self.path().into()
132+
}
133+
134+
fn file_name(&self) -> Cow<'_, OsStr> {
135+
self.file_name().into()
136+
}
137+
138+
fn file_type(&self) -> std::io::Result<FileType> {
139+
self.file_type()
140+
}
141+
}
142+
}
143+
115144
///
116145
#[cfg(feature = "fs-walkdir-parallel")]
117146
pub mod walkdir {

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ check:
9595
cargo check -p gix-features --all-features
9696
cargo check -p gix-features --features parallel
9797
cargo check -p gix-features --features fs-walkdir-parallel
98+
cargo check -p gix-features --features fs-read-dir
9899
cargo check -p gix-features --features rustsha1
99100
cargo check -p gix-features --features fast-sha1
100101
cargo check -p gix-features --features progress

0 commit comments

Comments
 (0)