fif/src/scan_error.rs

27 lines
581 B
Rust
Raw Normal View History

use std::fmt::{Display, Formatter, Result};
use std::path::Path;
2021-02-21 14:07:50 +00:00
#[derive(Debug)]
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<'_>) -> Result {
2021-02-18 09:48:38 +00:00
write!(
f,
"Couldn't {} file: {}",
2021-02-18 09:48:38 +00:00
match self {
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-18 09:48:38 +00:00
}