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
use alloc::string::String;

/// Convenience alias for [`Result`](core::result::Result) type for the library.
pub type Result<T> = core::result::Result<T, Error>;

/// Represents error types for the library.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Error {
    Io(String),
    DeviceTree(String),
    Svd(String),
    InvalidBitRange,
}

impl From<device_tree::Error> for Error {
    fn from(err: device_tree::Error) -> Self {
        Self::DeviceTree(format!("{err:?}"))
    }
}

#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Self {
        Self::Io(format!("{err}"))
    }
}

#[cfg(feature = "std")]
impl From<svd::SvdError> for Error {
    fn from(err: svd::SvdError) -> Self {
        Self::Svd(format!("{err}"))
    }
}

#[cfg(feature = "std")]
impl From<svd_encoder::EncodeError> for Error {
    fn from(err: svd_encoder::EncodeError) -> Error {
        Self::Svd(format!("{err}"))
    }
}