indexbus_blocking/
errors.rs

1use indexbus_core::Error as CoreError;
2
3/// Convenience `Result` type for blocking adapters.
4pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug)]
7/// Errors returned by blocking adapters.
8pub enum Error {
9    /// An error returned by `indexbus-core` APIs.
10    Core(CoreError),
11    /// A wait/wake error from `indexbus-wake`.
12    Wait(indexbus_wake::WaitError),
13    /// The layout does not advertise or contain the required wake sections.
14    MissingBlockingCapability,
15}
16
17impl From<CoreError> for Error {
18    fn from(value: CoreError) -> Self {
19        Self::Core(value)
20    }
21}
22
23impl From<indexbus_wake::WaitError> for Error {
24    fn from(value: indexbus_wake::WaitError) -> Self {
25        Self::Wait(value)
26    }
27}
28
29#[cfg(feature = "std")]
30impl std::fmt::Display for Error {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Self::Core(e) => write!(f, "core error: {e:?}"),
34            Self::Wait(e) => write!(f, "wait error: {e}"),
35            Self::MissingBlockingCapability => {
36                write!(f, "layout missing INDEXBUS_CAP_SUPPORTS_BLOCKING")
37            }
38        }
39    }
40}
41
42#[cfg(feature = "std")]
43impl std::error::Error for Error {}