apply clippy suggestions

This commit is contained in:
figsoda 2023-01-05 14:23:37 -05:00
parent b66932b5fb
commit e06b2c8635
7 changed files with 16 additions and 18 deletions

View File

@ -140,7 +140,7 @@ where
builder.append_file(path, file.file_mut()).map_err(|err| { builder.append_file(path, file.file_mut()).map_err(|err| {
FinalError::with_title("Could not create archive") FinalError::with_title("Could not create archive")
.detail("Unexpected error while trying to read file") .detail("Unexpected error while trying to read file")
.detail(format!("Error: {}.", err)) .detail(format!("Error: {err}."))
})?; })?;
} }
} }

View File

@ -146,7 +146,7 @@ pub fn run(
"You are trying to compress a folder." "You are trying to compress a folder."
}; };
let error = FinalError::with_title(format!("Cannot compress to '{}'.", output_path)) let error = FinalError::with_title(format!("Cannot compress to '{output_path}'."))
.detail(first_detail_message) .detail(first_detail_message)
.detail(format!( .detail(format!(
"The compression format '{}' does not accept multiple files.", "The compression format '{}' does not accept multiple files.",
@ -154,8 +154,8 @@ pub fn run(
)) ))
.detail("Formats that bundle files into an archive are .tar and .zip.") .detail("Formats that bundle files into an archive are .tar and .zip.")
.hint(format!("Try inserting '.tar' or '.zip' before '{}'.", &formats[0])) .hint(format!("Try inserting '.tar' or '.zip' before '{}'.", &formats[0]))
.hint(format!("From: {}", output_path)) .hint(format!("From: {output_path}"))
.hint(format!("To: {}", suggested_output_path)); .hint(format!("To: {suggested_output_path}"));
return Err(error.into()); return Err(error.into());
} }
@ -165,14 +165,12 @@ pub fn run(
"Cannot compress to '{}'.", "Cannot compress to '{}'.",
EscapedPathDisplay::new(&output_path) EscapedPathDisplay::new(&output_path)
)) ))
.detail(format!("Found the format '{}' in an incorrect position.", format)) .detail(format!("Found the format '{format}' in an incorrect position."))
.detail(format!( .detail(format!(
"'{}' can only be used at the start of the file extension.", "'{format}' can only be used at the start of the file extension."
format
)) ))
.hint(format!( .hint(format!(
"If you wish to compress multiple files, start the extension with '{}'.", "If you wish to compress multiple files, start the extension with '{format}'."
format
)) ))
.hint(format!( .hint(format!(
"Otherwise, remove the last '{}' from '{}'.", "Otherwise, remove the last '{}' from '{}'.",

View File

@ -76,7 +76,7 @@ impl Display for FinalError {
if is_running_in_accessible_mode() { if is_running_in_accessible_mode() {
write!(f, "\n{}hints:{}", *GREEN, *RESET)?; write!(f, "\n{}hints:{}", *GREEN, *RESET)?;
for hint in &self.hints { for hint in &self.hints {
write!(f, "\n{}", hint)?; write!(f, "\n{hint}")?;
} }
} else { } else {
for hint in &self.hints { for hint in &self.hints {
@ -138,7 +138,7 @@ impl fmt::Display for Error {
Error::Custom { reason } => reason.clone(), Error::Custom { reason } => reason.clone(),
}; };
write!(f, "{}", err) write!(f, "{err}")
} }
} }

View File

@ -57,7 +57,7 @@ fn print_entry(name: impl std::fmt::Display, is_dir: bool) {
if is_dir { if is_dir {
// if colors are deactivated, print final / to mark directories // if colors are deactivated, print final / to mark directories
if BLUE.is_empty() { if BLUE.is_empty() {
println!("{}/", name); println!("{name}/");
// if in ACCESSIBLE mode, use colors but print final / in case colors // if in ACCESSIBLE mode, use colors but print final / in case colors
// aren't read out aloud with a screen reader or aren't printed on a // aren't read out aloud with a screen reader or aren't printed on a
// braille reader // braille reader
@ -68,7 +68,7 @@ fn print_entry(name: impl std::fmt::Display, is_dir: bool) {
} }
} else { } else {
// not a dir -> just print the file name // not a dir -> just print the file name
println!("{}", name); println!("{name}");
} }
} }
@ -142,7 +142,7 @@ mod tree {
false => draw::FINAL_BRANCH, false => draw::FINAL_BRANCH,
}; };
print!("{}{}", prefix, final_part); print!("{prefix}{final_part}");
let is_dir = match self.file { let is_dir = match self.file {
Some(FileInArchive { is_dir, .. }) => is_dir, Some(FileInArchive { is_dir, .. }) => is_dir,
None => true, None => true,

View File

@ -31,7 +31,7 @@ pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;
fn main() { fn main() {
if let Err(err) = run() { if let Err(err) = run() {
eprintln!("{}", err); eprintln!("{err}");
std::process::exit(EXIT_FAILURE); std::process::exit(EXIT_FAILURE);
} }
} }

View File

@ -20,7 +20,7 @@ impl Display for EscapedPathDisplay<'_> {
let bstr = bstr::BStr::new(self.path.as_os_str().as_bytes()); let bstr = bstr::BStr::new(self.path.as_os_str().as_bytes());
write!(f, "{}", bstr) write!(f, "{bstr}")
} }
} }
@ -47,7 +47,7 @@ impl Display for EscapedPathDisplay<'_> {
/// See <https://gist.github.com/marcospb19/ebce5572be26397cf08bbd0fd3b65ac1> for a comparison. /// See <https://gist.github.com/marcospb19/ebce5572be26397cf08bbd0fd3b65ac1> for a comparison.
pub fn to_utf(os_str: &Path) -> Cow<str> { pub fn to_utf(os_str: &Path) -> Cow<str> {
let format = || { let format = || {
let text = format!("{:?}", os_str); let text = format!("{os_str:?}");
Cow::Owned(text.trim_matches('"').to_string()) Cow::Owned(text.trim_matches('"').to_string())
}; };

View File

@ -86,7 +86,7 @@ pub fn user_wants_to_continue(
let path = to_utf(strip_cur_dir(path)); let path = to_utf(strip_cur_dir(path));
let path = Some(&*path); let path = Some(&*path);
let placeholder = Some("FILE"); let placeholder = Some("FILE");
Confirmation::new(&format!("Do you want to {} 'FILE'?", action), placeholder).ask(path) Confirmation::new(&format!("Do you want to {action} 'FILE'?"), placeholder).ask(path)
} }
} }
} }