diff --git a/src/findings.rs b/src/findings.rs index 1b19183..6b1edc6 100644 --- a/src/findings.rs +++ b/src/findings.rs @@ -7,6 +7,7 @@ use crate::string_type::String; #[cfg(feature = "json")] use serde::{ser::SerializeStruct, Serializer}; +use std::fmt::{Display, Formatter}; /// Information about a scanned file. #[derive(Ord, PartialOrd, Eq, PartialEq)] @@ -40,3 +41,29 @@ impl<'a> Findings<'a> { mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].clone()) } } + +#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)] +#[cfg_attr(feature = "json", derive(serde::Serialize))] +#[cfg_attr(feature = "json", serde(tag = "type", content = "path"))] +pub enum ScanError<'a> { + /// Something went wrong while trying to read the given file. + File(&'a Path), + /// Failed to determine the mimetype of the given file. + Mime(&'a Path), +} + +impl<'a> Display for ScanError<'a> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Couldn't {} file: {}", + match self { + Self::File(_) => "read", + Self::Mime(_) => "determine mime type of", + }, + match self { + Self::File(f) | Self::Mime(f) => f.to_string_lossy(), + } + ) + } +} diff --git a/src/formats.rs b/src/formats.rs index 722144f..a9438b6 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -9,7 +9,7 @@ use std::path::Path; use cfg_if::cfg_if; use snailquote::escape; -use crate::scan_error::ScanError; +use crate::findings::ScanError; use crate::{Findings, BACKEND}; use itertools::Itertools; diff --git a/src/main.rs b/src/main.rs index fe260a0..5fbf3c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ use crate::findings::Findings; use crate::formats::{Format, PowerShell, Shell}; use crate::mime_db::MimeDb; use crate::parameters::{OutputFormat, ScanOpts}; -use crate::scan_error::ScanError; +use crate::findings::ScanError; use std::collections::BTreeSet; mod findings; @@ -41,7 +41,6 @@ mod formats; mod inspectors; mod mime_db; mod parameters; -mod scan_error; pub(crate) mod string_type; #[cfg(test)] diff --git a/src/scan_error.rs b/src/scan_error.rs deleted file mode 100644 index 2865c15..0000000 --- a/src/scan_error.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fmt::{Display, Formatter}; -use std::path::Path; - -#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)] -#[cfg_attr(feature = "json", derive(serde::Serialize))] -#[cfg_attr(feature = "json", serde(tag = "type", content = "path"))] -pub enum ScanError<'a> { - /// Something went wrong while trying to read the given file. - File(&'a Path), - /// Failed to determine the mimetype of the given file. - Mime(&'a Path), -} - -impl<'a> Display for ScanError<'a> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "Couldn't {} file: {}", - match self { - Self::File(_) => "read", - Self::Mime(_) => "determine mime type of", - }, - match self { - Self::File(f) | Self::Mime(f) => f.to_string_lossy(), - } - ) - } -}