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(), } ) } }