1use core::fmt;
11
12#[cfg(feature = "alloc")]
13use alloc::string::String;
14
15#[derive(Debug)]
16pub struct Error {
18 msg: String,
19}
20
21pub type Result<T> = core::result::Result<T, Error>;
23
24impl Error {
25 pub fn msg(msg: impl Into<String>) -> Self {
27 Self { msg: msg.into() }
28 }
29}
30
31impl fmt::Display for Error {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "{}", self.msg)
34 }
35}
36
37#[cfg(feature = "std")]
38impl std::error::Error for Error {}
39
40impl From<String> for Error {
41 fn from(value: String) -> Self {
42 Self::msg(value)
43 }
44}
45
46impl From<&str> for Error {
47 fn from(value: &str) -> Self {
48 Self::msg(value)
49 }
50}
51
52#[cfg(feature = "std")]
53impl From<std::io::Error> for Error {
54 fn from(value: std::io::Error) -> Self {
55 Self::msg(alloc::format!("{value}"))
56 }
57}
58
59#[cfg(feature = "std")]
60impl From<indexbus_transport_shm::Error> for Error {
61 fn from(value: indexbus_transport_shm::Error) -> Self {
62 Self::msg(alloc::format!("{value:?}"))
63 }
64}
65
66impl From<indexbus_core::Error> for Error {
67 fn from(value: indexbus_core::Error) -> Self {
68 Self::msg(alloc::format!("{value:?}"))
69 }
70}
71
72#[cfg(feature = "std")]
73impl From<indexbus_seq::Error> for Error {
74 fn from(value: indexbus_seq::Error) -> Self {
75 Self::msg(alloc::format!("{value:?}"))
76 }
77}
78
79#[cfg(feature = "std")]
80impl From<indexbus_log::Error> for Error {
81 fn from(value: indexbus_log::Error) -> Self {
82 Self::msg(alloc::format!("{value:?}"))
83 }
84}
85
86impl From<indexbus_typed::Error> for Error {
87 fn from(value: indexbus_typed::Error) -> Self {
88 Self::msg(alloc::format!("{value:?}"))
89 }
90}
91
92impl From<indexbus_adapters_core::TryRecvError> for Error {
93 fn from(value: indexbus_adapters_core::TryRecvError) -> Self {
94 Self::msg(alloc::format!("{value:?}"))
95 }
96}
97
98impl From<indexbus_adapters_core::TrySendError> for Error {
99 fn from(value: indexbus_adapters_core::TrySendError) -> Self {
100 Self::msg(alloc::format!("{value:?}"))
101 }
102}
103
104#[cfg(feature = "blocking")]
105impl From<indexbus_blocking::Error> for Error {
106 fn from(value: indexbus_blocking::Error) -> Self {
107 Self::msg(alloc::format!("{value:?}"))
108 }
109}