teaql_provider_linux/
error.rs1use std::fmt;
2
3#[derive(Debug)]
5pub enum LinuxProviderError {
6 UnknownEntity(String),
8 ProcFs(String),
10 Io(std::io::Error),
12}
13
14impl fmt::Display for LinuxProviderError {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 Self::UnknownEntity(name) => write!(f, "unknown entity: {name}"),
18 Self::ProcFs(msg) => write!(f, "procfs error: {msg}"),
19 Self::Io(err) => write!(f, "I/O error: {err}"),
20 }
21 }
22}
23
24impl std::error::Error for LinuxProviderError {
25 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26 match self {
27 Self::Io(err) => Some(err),
28 _ => None,
29 }
30 }
31}
32
33impl From<std::io::Error> for LinuxProviderError {
34 fn from(err: std::io::Error) -> Self {
35 Self::Io(err)
36 }
37}
38
39impl From<procfs::ProcError> for LinuxProviderError {
40 fn from(err: procfs::ProcError) -> Self {
41 Self::ProcFs(err.to_string())
42 }
43}