1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![cfg(any(target_os = "linux", target_os = "android"))]

/// define some macro_rule used in this crate.
#[macro_use]
mod macros;

pub mod _self;
pub mod pid;
pub mod proc;

/// all the funcitons return this error in the crate.
#[derive(Debug)]
pub enum ProcErr {
    /// Failed to read the corresponding file.
    IO(std::io::Error),
    Parse(Box<dyn std::error::Error>),
    BadFormat(String),
}

impl From<std::io::Error> for ProcErr {
    fn from(x: std::io::Error) -> Self {
        ProcErr::IO(x)
    }
}

impl From<std::num::ParseIntError> for ProcErr {
    fn from(x: std::num::ParseIntError) -> Self {
        ProcErr::Parse(Box::new(x))
    }
}

impl From<std::num::ParseFloatError> for ProcErr {
    fn from(x: std::num::ParseFloatError) -> Self {
        ProcErr::Parse(Box::new(x))
    }
}

impl From<String> for ProcErr {
    fn from(s: String) -> Self {
        ProcErr::BadFormat(s)
    }
}

impl From<&str> for ProcErr {
    fn from(s: &str) -> Self {
        ProcErr::BadFormat(s.to_string())
    }
}