1#[cfg(feature = "alloc")]
8use alloc::{boxed::Box, string::String};
9
10pub type Result<T = ()> = core::result::Result<T, Error>;
12
13#[derive(Debug, thiserror::Error)]
14#[non_exhaustive]
15pub enum Error {
16 #[error(transparent)]
17 StateError(#[from] scsys_state::error::Error),
18 #[error(transparent)]
19 #[cfg(feature = "time")]
20 TimeError(#[from] scsys_time::error::Error),
21 #[cfg(feature = "alloc")]
22 #[error(transparent)]
23 BoxError(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
24 #[error(transparent)]
25 FmtError(#[from] core::fmt::Error),
26 #[cfg(feature = "std")]
27 #[error(transparent)]
28 IoError(#[from] std::io::Error),
29 #[cfg(feature = "json")]
30 #[error(transparent)]
31 JsonError(#[from] serde_json::Error),
32 #[cfg(feature = "alloc")]
33 #[error("Unknown error: {0}")]
34 Unknown(String),
35}
36
37#[cfg(feature = "alloc")]
38mod impl_alloc {
39 use super::Error;
40 use alloc::{boxed::Box, string::String};
41
42 impl Error {
43 pub fn box_error<E>(error: E) -> Self
44 where
45 E: core::error::Error + Send + Sync + 'static,
46 {
47 Self::BoxError(Box::new(error))
48 }
49 }
50
51 impl From<String> for Error {
52 fn from(value: String) -> Self {
53 Self::Unknown(value)
54 }
55 }
56
57 impl From<&str> for Error {
58 fn from(value: &str) -> Self {
59 Self::Unknown(String::from(value))
60 }
61 }
62}