diff --git a/src/extension.rs b/src/extension.rs index 24465c03b..5e6740784 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -6,6 +6,7 @@ use self::CompressionFormat::*; /// A wrapper around `CompressionFormat` that allows combinations like `tgz` #[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] pub struct Extension { /// One extension like "tgz" can be made of multiple CompressionFormats ([Tar, Gz]) pub compression_formats: &'static [CompressionFormat], @@ -35,7 +36,7 @@ impl Extension { impl fmt::Display for Extension { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(&self.display_text) + self.display_text.fmt(f) } } diff --git a/src/utils.rs b/src/utils.rs index 79bdf8c75..60248ab1d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,7 @@ //! Random stuff used on ouch. use std::{ + borrow::Cow, cmp, env, ffi::OsStr, io, @@ -109,12 +110,12 @@ pub fn concatenate_list_of_os_str(os_strs: &[impl AsRef]) -> String { } /// Display the directory name, but change to "current directory" when necessary. -pub fn nice_directory_display(os_str: impl AsRef) -> String { - let text = to_utf(os_str); - if text == "." { - "current directory".to_string() +pub fn nice_directory_display(os_str: impl AsRef) -> Cow<'static, str> { + if os_str.as_ref() == "." { + Cow::Borrowed("current directory") } else { - format!("'{}'", text) + let text = to_utf(os_str); + Cow::Owned(format!("'{}'", text)) } }