rlink/core/
error.rs

1pub type Result<T> = core::result::Result<T, Error>;
2
3#[derive(Debug)]
4pub struct Error {
5    pub(crate) inner_error: anyhow::Error,
6}
7
8impl<'a> From<&'a str> for Error {
9    fn from(msg: &'a str) -> Self {
10        Error {
11            inner_error: anyhow!(msg.to_string()),
12        }
13    }
14}
15
16impl From<String> for Error {
17    fn from(msg: String) -> Self {
18        Error {
19            inner_error: anyhow!(msg),
20        }
21    }
22}
23
24impl From<anyhow::Error> for Error {
25    fn from(e: anyhow::Error) -> Self {
26        Error { inner_error: e }
27    }
28}
29
30impl Error {
31    pub fn wrap<E>(e: E) -> Self
32    where
33        E: std::error::Error + Into<anyhow::Error>,
34    {
35        Error {
36            inner_error: anyhow!(e),
37        }
38    }
39}
40
41impl std::error::Error for Error {}
42
43impl std::fmt::Display for Error {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        self.inner_error.fmt(f)
46    }
47}