From e0cba4b700a8846629d9e6cb91fa032bdd4a249b Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 3 Apr 2020 12:02:59 +0200 Subject: [PATCH] Remove 'internal' module --- src/fshelper/mod.rs | 18 ++++++++++++++++++ src/internal/mod.rs | 18 ------------------ src/main.rs | 1 - src/walk.rs | 5 ++--- 4 files changed, 20 insertions(+), 22 deletions(-) delete mode 100644 src/internal/mod.rs diff --git a/src/fshelper/mod.rs b/src/fshelper/mod.rs index 933416a..e4fbd03 100644 --- a/src/fshelper/mod.rs +++ b/src/fshelper/mod.rs @@ -1,4 +1,6 @@ +use std::borrow::Cow; use std::env::current_dir; +use std::ffi::OsStr; use std::fs; use std::io; #[cfg(any(unix, target_os = "redox"))] @@ -64,3 +66,19 @@ pub fn is_empty(entry: &walk::DirEntry) -> bool { false } } + +#[cfg(any(unix, target_os = "redox"))] +pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> { + use std::os::unix::ffi::OsStrExt; + Cow::Borrowed(input.as_bytes()) +} + +#[cfg(windows)] +pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> { + let string = input.to_string_lossy(); + + match string { + Cow::Owned(string) => Cow::Owned(string.into_bytes()), + Cow::Borrowed(string) => Cow::Borrowed(string.as_bytes()), + } +} diff --git a/src/internal/mod.rs b/src/internal/mod.rs deleted file mode 100644 index f8398a1..0000000 --- a/src/internal/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::borrow::Cow; -use std::ffi::OsStr; - -#[cfg(any(unix, target_os = "redox"))] -pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> { - use std::os::unix::ffi::OsStrExt; - Cow::Borrowed(input.as_bytes()) -} - -#[cfg(windows)] -pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> { - let string = input.to_string_lossy(); - - match string { - Cow::Owned(string) => Cow::Owned(string.into_bytes()), - Cow::Borrowed(string) => Cow::Borrowed(string.as_bytes()), - } -} diff --git a/src/main.rs b/src/main.rs index 193515a..5f39eec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ mod exit_codes; mod filetypes; mod filter; mod fshelper; -mod internal; mod options; mod output; mod regex_helper; diff --git a/src/walk.rs b/src/walk.rs index 819d61e..e818c9e 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -1,7 +1,6 @@ use crate::exec; use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::fshelper; -use crate::internal::osstr_to_bytes; use crate::options::Options; use crate::output; @@ -362,14 +361,14 @@ fn spawn_senders( } }; - if !pattern.is_match(&osstr_to_bytes(search_str.as_ref())) { + if !pattern.is_match(&fshelper::osstr_to_bytes(search_str.as_ref())) { return ignore::WalkState::Continue; } // Filter out unwanted extensions. if let Some(ref exts_regex) = config.extensions { if let Some(path_str) = entry_path.file_name() { - if !exts_regex.is_match(&osstr_to_bytes(path_str)) { + if !exts_regex.is_match(&fshelper::osstr_to_bytes(path_str)) { return ignore::WalkState::Continue; } } else {