Skip to content

Commit 3b0c35a

Browse files
committed
Use Box<Path> instead of PathBuf
1 parent 778365d commit 3b0c35a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Result<Paths, PatternE
200200
}
201201

202202
#[cfg(windows)]
203-
fn to_scope(p: &Path) -> PathBuf {
203+
fn to_scope(p: &Path) -> Box<Path> {
204204
// FIXME handle volume relative paths here
205-
p.to_path_buf()
205+
p.into()
206206
}
207207
#[cfg(not(windows))]
208-
fn to_scope(p: &Path) -> PathBuf {
209-
p.to_path_buf()
208+
fn to_scope(p: &Path) -> Box<Path> {
209+
p.into()
210210
}
211211

212212
// make sure that the pattern is valid first, else early return with error
@@ -243,7 +243,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Result<Paths, PatternE
243243
});
244244
}
245245

246-
let scope = root.map_or_else(|| PathBuf::from("."), to_scope);
246+
let scope = root.map_or_else(|| Path::new(".").into(), to_scope);
247247
let scope = PathWrapper::from_path(scope);
248248

249249
let mut dir_patterns = Vec::new();
@@ -328,13 +328,13 @@ impl fmt::Display for GlobError {
328328

329329
#[derive(Debug)]
330330
struct PathWrapper {
331-
path: PathBuf,
331+
path: Box<Path>,
332332
is_directory: bool,
333333
file_name: Option<Box<OsStr>>,
334334
}
335335

336336
impl PathWrapper {
337-
fn from_dir_entry(path: PathBuf, file_name: Option<Box<OsStr>>, e: DirEntry) -> Self {
337+
fn from_dir_entry(path: Box<Path>, file_name: Option<Box<OsStr>>, e: DirEntry) -> Self {
338338
let is_directory = e
339339
.file_type()
340340
.ok()
@@ -355,7 +355,7 @@ impl PathWrapper {
355355
file_name,
356356
}
357357
}
358-
fn from_path(path: PathBuf) -> Self {
358+
fn from_path(path: Box<Path>) -> Self {
359359
let is_directory = fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false);
360360
let file_name = path.file_name().map(Box::from);
361361
Self {
@@ -366,7 +366,7 @@ impl PathWrapper {
366366
}
367367

368368
fn into_path(self) -> PathBuf {
369-
self.path
369+
self.path.into_path_buf()
370370
}
371371
}
372372

@@ -928,7 +928,7 @@ fn fill_todo(
928928
} else {
929929
path.join(&s)
930930
};
931-
let next_path = PathWrapper::from_path(next_path);
931+
let next_path = PathWrapper::from_path(next_path.into_boxed_path());
932932
if (special && is_dir)
933933
|| (!special
934934
&& (fs::metadata(&next_path).is_ok()
@@ -944,9 +944,9 @@ fn fill_todo(
944944
let (path, file_name) = if curdir {
945945
let path = e.path();
946946
let file_name = path.file_name().unwrap();
947-
(PathBuf::from(file_name), Some(Box::from(file_name)))
947+
(Box::from(file_name.as_ref()), Some(Box::from(file_name)))
948948
} else {
949-
let path = e.path();
949+
let path = e.path().into_boxed_path();
950950
let file_name = path.file_name().map(Box::from);
951951
(path, file_name)
952952
};
@@ -972,7 +972,10 @@ fn fill_todo(
972972
if !pattern.tokens.is_empty() && pattern.tokens[0] == Char('.') {
973973
for &special in &[".", ".."] {
974974
if pattern.matches_with(special, options) {
975-
add(todo, PathWrapper::from_path(path.join(special)));
975+
add(
976+
todo,
977+
PathWrapper::from_path(path.join(special).into_boxed_path()),
978+
);
976979
}
977980
}
978981
}

0 commit comments

Comments
 (0)