1 //! Random and miscellaneous utils used in ouch.
3 //! In here we have the logic for custom formatting, some file and directory utils, and user
4 //! stdin interaction helpers.
15 file_visibility::FileVisibilityPolicy,
17 nice_directory_display, os_str_to_str, path_to_str, pretty_format_list_of_paths, strip_cur_dir, Bytes,
21 cd_into_same_dir_as, clear_path, create_dir_if_non_existent, is_path_stdin, remove_file_or_dir,
24 question::{ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy},
25 utf8::{get_invalid_utf8_paths, is_invalid_utf8},
29 use std::{ffi::OsStr, path::PathBuf};
31 /// Check, without allocating, if os_str can be converted into &str
32 pub fn is_invalid_utf8(os_str: impl AsRef<OsStr>) -> bool {
33 os_str.as_ref().to_str().is_none()
36 /// Filter out list of paths that are not utf8 valid
37 pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec<&PathBuf> {
38 paths.iter().filter(|path| is_invalid_utf8(path)).collect()