use core::fmt;
use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
NotFound,
InvalidTarget(String),
IoError(std::io::Error),
UnmountFailed {
path: PathBuf,
fstype: String,
reason: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::NotFound => write!(f, "path not found"),
Error::InvalidTarget(reason) => write!(f, "{}", reason),
Error::IoError(e) => e.fmt(f),
Error::UnmountFailed {
path,
fstype,
reason,
} => write!(
f,
"cannot unmount '{}' ({}): {}",
path.display(),
fstype,
reason,
),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::IoError(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Error::IoError(err)
}
}