diff --git a/src/filesystem.rs b/src/filesystem.rs index 846b11b..0aa2441 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -93,13 +93,8 @@ pub fn strip_current_dir(pathbuf: &PathBuf) -> &Path { iter.as_path() } -pub fn replace_path_separator<'a>(path_separator: &Option, path: &mut Cow<'a, str>) { - match &path_separator { - None => {} - Some(sep) => { - *path.to_mut() = path.replace(std::path::MAIN_SEPARATOR, &sep); - } - } +pub fn replace_path_separator<'a>(path: &str, new_path_separator: &str) -> String { + path.replace(std::path::MAIN_SEPARATOR, &new_path_separator) } #[cfg(test)] diff --git a/src/output.rs b/src/output.rs index 1d6c100..fcc9ed7 100644 --- a/src/output.rs +++ b/src/output.rs @@ -53,7 +53,9 @@ fn print_entry_colorized( .unwrap_or(default_style); let mut path_string = component.to_string_lossy(); - replace_path_separator(&config.path_separator, &mut path_string); + if let Some(ref separator) = config.path_separator { + *path_string.to_mut() = replace_path_separator(&path_string, &separator); + } write!(stdout, "{}", style.paint(path_string))?; // TODO: can we move this out of the if-statement? Why do we call it that often? @@ -78,7 +80,9 @@ fn print_entry_uncolorized( ) -> io::Result<()> { let separator = if config.null_separator { "\0" } else { "\n" }; - let mut path_str = path.to_string_lossy(); - replace_path_separator(&config.path_separator, &mut path_str); - write!(stdout, "{}{}", path_str, separator) + let mut path_string = path.to_string_lossy(); + if let Some(ref separator) = config.path_separator { + *path_string.to_mut() = replace_path_separator(&path_string, &separator); + } + write!(stdout, "{}{}", path_string, separator) }