2021-02-14 17:12:27 +00:00
|
|
|
use std::fmt::{Display, Formatter, Result};
|
2021-03-01 09:18:20 +00:00
|
|
|
use std::path::PathBuf;
|
2021-02-14 17:12:27 +00:00
|
|
|
|
2021-02-21 14:07:50 +00:00
|
|
|
#[derive(Debug)]
|
2021-02-10 09:20:22 +00:00
|
|
|
pub enum ScanError {
|
2021-02-28 14:06:05 +00:00
|
|
|
/// Something went wrong while trying to read the given file.
|
2021-03-01 09:18:20 +00:00
|
|
|
File(PathBuf),
|
2021-02-28 14:06:05 +00:00
|
|
|
/// Failed to determine the mimetype of the given file.
|
2021-03-01 09:18:20 +00:00
|
|
|
Mime(PathBuf),
|
2021-02-14 17:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for ScanError {
|
|
|
|
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
|
|
|
}
|