1use core::fmt::{Display, Formatter};
2
3#[derive(Debug)]
4pub enum Error {
5 NoMemory,
6 Layout,
7 Dma(dma_api::DmaError),
8 Mmio(mmio_api::MapError),
9 Unknown(&'static str),
10}
11
12pub type Result<T = ()> = core::result::Result<T, Error>;
13
14impl From<dma_api::DmaError> for Error {
15 fn from(value: dma_api::DmaError) -> Self {
16 match value {
17 dma_api::DmaError::NoMemory => Self::NoMemory,
18 dma_api::DmaError::LayoutError(_) => Self::Layout,
19 other => Self::Dma(other),
20 }
21 }
22}
23
24impl From<mmio_api::MapError> for Error {
25 fn from(value: mmio_api::MapError) -> Self {
26 Self::Mmio(value)
27 }
28}
29
30impl Display for Error {
31 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
32 match self {
33 Self::NoMemory => f.write_str("no memory available"),
34 Self::Layout => f.write_str("invalid memory layout"),
35 Self::Dma(err) => write!(f, "dma error: {err}"),
36 Self::Mmio(err) => write!(f, "mmio map error: {err}"),
37 Self::Unknown(message) => f.write_str(message),
38 }
39 }
40}
41
42impl core::error::Error for Error {}