1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug)]
8pub enum Error {
9 Io(std::io::Error),
11 FromVecWithNul(std::ffi::FromVecWithNulError),
13 Utf8(std::str::Utf8Error),
15 FromUtf8(std::string::FromUtf8Error),
17 ParseInt(std::num::ParseIntError),
19 InvalidData,
21
22 #[cfg(target_os = "linux")]
23 Procmaps(procmaps::Error),
25
26 #[cfg(target_os = "macos")]
27 Regex(regex::Error),
29 #[cfg(target_os = "macos")]
30 Mach(i32),
32 #[cfg(target_os = "macos")]
33 Libproc,
35
36 #[cfg(target_os = "windows")]
37 Layout(std::alloc::LayoutError),
39}
40
41impl fmt::Display for Error {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 match self {
49 Self::Io(x) => write!(f, "IO error; err = {:?}", x),
50 Self::FromVecWithNul(x) => write!(f, "FromVecWithNul error; err = {:?}", x),
51 Self::Utf8(x) => write!(f, "UTF8 error; err = {:?}", x),
52 Self::FromUtf8(x) => write!(f, "FromUTF8 error; err = {:?}", x),
53 Self::ParseInt(x) => write!(f, "ParseInt error; err = {:?}", x),
54 Self::InvalidData => write!(f, "invalid data encountered"),
55
56 #[cfg(target_os = "linux")]
57 Self::Procmaps(x) => write!(f, "procmaps error; err = {:?}", x),
58
59 #[cfg(target_os = "macos")]
60 Self::Regex(x) => write!(f, "regex error; err = {:?}", x),
61 #[cfg(target_os = "macos")]
62 Self::Mach(x) => write!(f, "mach error code {}", x),
63 #[cfg(target_os = "macos")]
64 Self::Libproc => write!(f, "libproc error"),
65
66 #[cfg(target_os = "windows")]
67 Self::Layout(x) => write!(f, "Layout error; err = {:?}", x),
68 }
69 }
70}