2021-02-14 17:12:27 +00:00
|
|
|
use std::fmt::{Display, Formatter, Result};
|
2021-03-11 17:26:35 +00:00
|
|
|
use std::path::Path;
|
2021-02-14 17:12:27 +00:00
|
|
|
|
2021-02-21 14:07:50 +00:00
|
|
|
#[derive(Debug)]
|
2021-03-11 17:26:35 +00:00
|
|
|
pub enum ScanError<'a> {
|
2021-02-28 14:06:05 +00:00
|
|
|
/// Something went wrong while trying to read the given file.
|
2021-03-11 17:26:35 +00:00
|
|
|
File(&'a Path),
|
2021-02-28 14:06:05 +00:00
|
|
|
/// Failed to determine the mimetype of the given file.
|
2021-03-11 17:26:35 +00:00
|
|
|
Mime(&'a Path),
|
2021-02-14 17:12:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 17:26:35 +00:00
|
|
|
impl<'a> Display for ScanError<'a> {
|
2021-02-14 17:12:27 +00:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
2021-02-18 09:48:38 +00:00
|
|
|
write!(
|
|
|
|
f,
|
2021-03-01 09:18:20 +00:00
|
|
|
"Couldn't {} file: {}",
|
2021-02-18 09:48:38 +00:00
|
|
|
match self {
|
2021-03-01 09:18:20 +00:00
|
|
|
Self::File(_) => "read",
|
|
|
|
Self::Mime(_) => "determine mime type of",
|
|
|
|
},
|
|
|
|
match self {
|
2021-03-01 10:20:46 +00:00
|
|
|
Self::File(f) | Self::Mime(f) => f.to_string_lossy(),
|
2021-02-18 09:48:38 +00:00
|
|
|
}
|
2021-02-14 17:12:27 +00:00
|
|
|
)
|
|
|
|
}
|
2021-02-18 09:48:38 +00:00
|
|
|
}
|