Skip to content

Commit

Permalink
Use Box<OsStr> instead of OsString for filename storage
Browse files Browse the repository at this point in the history
  • Loading branch information
osiewicz committed Dec 30, 2024
1 parent b7dbb48 commit 778365d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ doctest!("../README.md");
use std::cmp;
use std::cmp::Ordering;
use std::error::Error;
use std::ffi::OsString;
use std::ffi::OsStr;
use std::fmt;
use std::fs;
use std::fs::DirEntry;
Expand Down Expand Up @@ -330,11 +330,11 @@ impl fmt::Display for GlobError {
struct PathWrapper {
path: PathBuf,
is_directory: bool,
file_name: Option<OsString>,
file_name: Option<Box<OsStr>>,
}

impl PathWrapper {
fn from_dir_entry(path: PathBuf, file_name: Option<OsString>, e: DirEntry) -> Self {
fn from_dir_entry(path: PathBuf, file_name: Option<Box<OsStr>>, e: DirEntry) -> Self {
let is_directory = e
.file_type()
.ok()
Expand All @@ -357,7 +357,7 @@ impl PathWrapper {
}
fn from_path(path: PathBuf) -> Self {
let is_directory = fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false);
let file_name = path.file_name().map(ToOwned::to_owned);
let file_name = path.file_name().map(Box::from);
Self {
path,
is_directory,
Expand Down Expand Up @@ -944,10 +944,10 @@ fn fill_todo(
let (path, file_name) = if curdir {
let path = e.path();
let file_name = path.file_name().unwrap();
(PathBuf::from(file_name), Some(file_name.to_owned()))
(PathBuf::from(file_name), Some(Box::from(file_name)))
} else {
let path = e.path();
let file_name = path.file_name().map(ToOwned::to_owned);
let file_name = path.file_name().map(Box::from);
(path, file_name)
};
PathWrapper::from_dir_entry(path, file_name, e)
Expand Down

0 comments on commit 778365d

Please sign in to comment.