diff --git a/src/formats.rs b/src/formats.rs index bc598ff..10af6f3 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -14,7 +14,7 @@ use crate::{Findings, BACKEND}; const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); #[doc(hidden)] -type Entries = [Result]; +type Entries = [Result]; enum Writable<'a> { String(&'a str), @@ -86,11 +86,11 @@ pub trait Format { Err(error) => { // something went wrong 0uo - match error.0 { + match error { // failed to read the file - ScanError::File => self.unreadable(f, &error.1)?, + ScanError::File(path) => self.unreadable(f, path)?, // file was read successfully, but we couldn't determine a mimetype - ScanError::Mime => self.unknown_type(f, &error.1)?, + ScanError::Mime(path) => self.unknown_type(f, path)?, } } } diff --git a/src/main.rs b/src/main.rs index 7784db0..30b27ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,7 @@ fn main() { r.recommended_extension().unwrap_or_else(|| "???".into()) ) } - Err(f) => warn!("{:#?}: Error 0uo - {}", f.1, f.0), + Err(f) => warn!("Error 0uo - {}", f), } } @@ -191,26 +191,26 @@ fn extension_from_path(path: &Path) -> Option { map(|e| String::from(e.to_string_lossy())) // Convert from OsStr to String } -/// Inspects the given entry, returning a [Findings] on success and a tuple of [ScanError] and [PathBuf] on failure. +/// Inspects the given entry, returning a [Findings] on success and a [ScanError] on failure. /// /// In the event of an IO error, the returned ScanError will be of type [ScanError::File]. Otherwise, a /// [ScanError::Mime] will be returned, meaning that the file was scanned successfully, but a mimetype could not be /// determined. -fn scan_file(entry: &DirEntry) -> Result { +fn scan_file(entry: &DirEntry) -> Result { // try to determine mimetype for this entry let result = inspectors::mime_type(MIMEDB.get().unwrap(), entry.path()); if result.is_err() { // an error occurred while trying to read the file // error!("{}: {}", entry.path().to_string_lossy(), error); - return Err((ScanError::File, entry.path().to_path_buf())); + return Err(ScanError::File(entry.path().to_path_buf())); } let result = result.unwrap(); if result.is_none() { // the file was read successfully, but we were unable to determine its mimetype // warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy()); - return Err((ScanError::Mime, entry.path().to_path_buf())); + return Err(ScanError::Mime(entry.path().to_path_buf())); } let result = result.unwrap(); @@ -235,7 +235,7 @@ fn scan_file(entry: &DirEntry) -> Result { } /// Takes a slice of [DirEntry]s and calls [scan_file] on each one, returning the results in a vector. -fn scan_from_walkdir(entries: &[DirEntry]) -> Vec> { +fn scan_from_walkdir(entries: &[DirEntry]) -> Vec> { cfg_if! { if #[cfg(feature = "multi-threaded")] { // rather than using a standard par_iter, split the entries into chunks of 32 first. diff --git a/src/parameters.rs b/src/parameters.rs index 4dc33a2..a568f4b 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -27,7 +27,7 @@ pub struct Parameters { )] pub exts: Option>>, - /// write good docs 0uo + /// Use a preset list of extensions as the search filter #[clap(short = 'E', long, arg_enum, required_unless_present = "exts")] pub ext_set: Option, diff --git a/src/scanerror.rs b/src/scanerror.rs index 6b2052f..bec5066 100644 --- a/src/scanerror.rs +++ b/src/scanerror.rs @@ -1,21 +1,25 @@ use std::fmt::{Display, Formatter, Result}; +use std::path::PathBuf; #[derive(Debug)] pub enum ScanError { /// Something went wrong while trying to read the given file. - File, + File(PathBuf), /// Failed to determine the mimetype of the given file. - Mime, + Mime(PathBuf), } impl Display for ScanError { fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!( f, - "{}", + "Couldn't {} file: {}", match self { - Self::File => "Couldn't read file", - Self::Mime => "Couldn't determine mime type", + Self::File(_) => "read", + Self::Mime(_) => "determine mime type of", + }, + match self { + Self::File(f) | Self::Mime(f) => f.to_string_lossy() } ) }