use std::fmt;
#[derive(Debug)]
pub enum LinuxProviderError {
UnknownEntity(String),
ProcFs(String),
Io(std::io::Error),
}
impl fmt::Display for LinuxProviderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownEntity(name) => write!(f, "unknown entity: {name}"),
Self::ProcFs(msg) => write!(f, "procfs error: {msg}"),
Self::Io(err) => write!(f, "I/O error: {err}"),
}
}
}
impl std::error::Error for LinuxProviderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for LinuxProviderError {
fn from(err: std::io::Error) -> Self {
Self::Io(err)
}
}
impl From<procfs::ProcError> for LinuxProviderError {
fn from(err: procfs::ProcError) -> Self {
Self::ProcFs(err.to_string())
}
}