diff --git a/rustfmt.toml b/rustfmt.toml index a60f155..6302064 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -7,3 +7,5 @@ hard_tabs = true tab_spaces = 2 newline_style = "Unix" group_imports = "StdExternalCrate" +array_width = 100 +fn_call_width = 80 diff --git a/src/files.rs b/src/files.rs index 1c5df02..c603133 100644 --- a/src/files.rs +++ b/src/files.rs @@ -209,11 +209,7 @@ pub fn scan_directory( // TODO: is there a way to just say `map_or(x, |y| y).thing()` instead of `map_or(x.thing(), |y| y.thing())`? // i don't care whether i'm returning a walkdir error or an io error, i just care about whether or not it // implements ToString (which they both do). map_or doesn't work on trait objects though :( - error!( - "{}: {}", - path, - err.io_error().map_or(err.to_string(), |e| e.to_string()) - ); + error!("{}: {}", path, err.io_error().map_or(err.to_string(), |e| e.to_string())); return None; } e.ok() @@ -353,23 +349,14 @@ pub fn mime_extension_lookup(essence: String) -> Option> { } else if essence == "application/zip" { // neither xdg-mime nor infer seem to be able to detect office XML files properly... [ - vec![ - String::from("zip"), - String::from("docx"), - String::from("xlsx"), - String::from("pptx"), - ], + vec![String::from("zip"), String::from("docx"), String::from("xlsx"), String::from("pptx")], possible_exts, ] .concat() } else if essence == "application/x-ms-dos-executable" { // .dll, .exe, and .scr files are given the same mime type... but you definitely don't want to rename one to the // other! - [ - vec![String::from("dll"), String::from("exe"), String::from("scr")], - possible_exts, - ] - .concat() + [vec![String::from("dll"), String::from("exe"), String::from("scr")], possible_exts].concat() } else { possible_exts }) @@ -381,6 +368,8 @@ pub fn mime_extension_lookup(essence: String) -> Option> { cache.insert(essence, exts.clone()); exts } else { + // this should only ever happen if cache.insert() hangs on another thread; i.e., close enough to "never" that + // marking this as unreachable should be fine unreachable!() } } diff --git a/src/formats.rs b/src/formats.rs index 5bb4d75..4c16a17 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -179,14 +179,7 @@ impl FormatSteps for Shell { fn no_known_extension(&self, f: &mut W, path: &Path) -> io::Result<()> { smart_write( f, - writablesln![ - "cat <<- '???'", - Newline, - "No known extension for ", - path, - Newline, - "???" - ], + writablesln!["cat <<- '???'", Newline, "No known extension for ", path, Newline, "???"], ) } @@ -199,10 +192,7 @@ impl FormatSteps for Shell { } fn header(&self, f: &mut W) -> io::Result<()> { - smart_write( - f, - writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())], - )?; + smart_write(f, writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())])?; if let Ok(working_directory) = std::env::current_dir() { smart_write(f, writablesln!["# Run from ", (working_directory.as_path())])?; @@ -232,26 +222,14 @@ impl FormatSteps for PowerShell { // there doesn't seem to be a way to rename the file, prompting only if the target already exists. smart_write( f, - writablesln![ - "Rename-Item -Verbose -Path ", - from, - " -NewName ", - (to.file_name().unwrap()) - ], + writablesln!["Rename-Item -Verbose -Path ", from, " -NewName ", (to.file_name().unwrap())], ) } fn no_known_extension(&self, f: &mut W, path: &Path) -> io::Result<()> { smart_write( f, - writablesln![ - "Write-Output @'", - Newline, - "No known extension for ", - path, - Newline, - "'@" - ], + writablesln!["Write-Output @'", Newline, "No known extension for ", path, Newline, "'@"], ) } diff --git a/src/parameters.rs b/src/parameters.rs index 68a3b9d..2629366 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -319,12 +319,7 @@ impl ExtensionSet { Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(), Self::Video => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(), - Self::Media => [ - Self::Images.extensions(), - Self::Audio.extensions(), - Self::Video.extensions(), - ] - .concat(), + Self::Media => [Self::Images.extensions(), Self::Audio.extensions(), Self::Video.extensions()].concat(), Self::Documents => vec![ "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps", "pages", "key", "numbers", diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 89e55fd..8f26db8 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -141,10 +141,7 @@ fn simple_directory() { // 3. ensure the recommended extension for "wrong.jpg" is "png" assert_eq!(&result.recommended_extension().unwrap(), &String::from("png")); // 4. ensure the recommended filename for "wrong.jpg" is "wrong.png" - assert_eq!( - result.recommended_path().unwrap().file_name(), - Some(OsStr::new("wrong.png")) - ); + assert_eq!(result.recommended_path().unwrap().file_name(), Some(OsStr::new("wrong.png"))); continue; } @@ -470,10 +467,7 @@ fn verbosity() { #[test] /// Ensures `os_name()`'s output is the same as [`std::env::consts::OS`], capitalisation notwithstanding fn validate_os_name() { - assert_eq!( - fif::utils::os_name().to_lowercase(), - std::env::consts::OS.to_lowercase() - ); + assert_eq!(fif::utils::os_name().to_lowercase(), std::env::consts::OS.to_lowercase()); } #[test]