lddtree/
errors.rs

1use std::error;
2use std::fmt;
3use std::io;
4
5use crate::ld_so_conf::LdSoConfError;
6
7#[derive(Debug)]
8pub enum Error {
9    Io(io::Error),
10    Goblin(goblin::error::Error),
11    LdSoConf(LdSoConfError),
12}
13
14impl fmt::Display for Error {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Error::Io(e) => e.fmt(f),
18            Error::Goblin(e) => e.fmt(f),
19            Error::LdSoConf(e) => e.fmt(f),
20        }
21    }
22}
23
24impl error::Error for Error {
25    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
26        match self {
27            Error::Io(e) => e.source(),
28            Error::Goblin(e) => e.source(),
29            Error::LdSoConf(e) => e.source(),
30        }
31    }
32}
33
34impl From<io::Error> for Error {
35    fn from(e: io::Error) -> Self {
36        Error::Io(e)
37    }
38}
39
40impl From<goblin::error::Error> for Error {
41    fn from(e: goblin::error::Error) -> Self {
42        Error::Goblin(e)
43    }
44}
45
46impl From<LdSoConfError> for Error {
47    fn from(e: LdSoConfError) -> Self {
48        Error::LdSoConf(e)
49    }
50}