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)]
16#[non_exhaustive]
17pub enum Error {
18 #[cfg(feature = "anyhow")]
19 #[error(transparent)]
20 AnyError(#[from] anyhow::Error),
21 #[cfg(feature = "alloc")]
22 #[error(transparent)]
23 BoxError(#[from] Box<dyn core::error::Error + Send + Sync>),
24 #[error(transparent)]
25 FmtError(#[from] core::fmt::Error),
26 #[cfg(feature = "json")]
27 #[error(transparent)]
28 JsonError(#[from] serde_json::Error),
29 #[cfg(feature = "std")]
30 #[error(transparent)]
31 IOError(#[from] std::io::Error),
32 #[cfg(feature = "alloc")]
33 #[error("Unknown error: {0}")]
34 UnknownError(String),
35}
36
37#[cfg(feature = "alloc")]
38impl From<String> for Error {
39 fn from(value: String) -> Self {
40 Error::UnknownError(value)
41 }
42}
43
44#[cfg(feature = "alloc")]
45impl From<&str> for Error {
46 fn from(value: &str) -> Self {
47 Error::UnknownError(String::from(value))
48 }
49}