pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("The impossible has occurred...")]
Infallible(#[from] core::convert::Infallible),
#[cfg(feature = "alloc")]
#[error(transparent)]
BoxError(#[from] alloc::boxed::Box<dyn core::error::Error + Send + Sync + 'static>),
#[error(transparent)]
FmtError(#[from] core::fmt::Error),
#[cfg(feature = "std")]
#[error(transparent)]
IOError(#[from] std::io::Error),
#[cfg(feature = "alloc")]
#[error("Unknown Error: {0}")]
Unknown(alloc::string::String),
}
#[cfg(feature = "alloc")]
mod impl_alloc {
use super::Error;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
impl Error {
pub fn box_error<E>(error: E) -> Self
where
E: core::error::Error + Send + Sync + 'static,
{
Self::BoxError(Box::new(error))
}
pub fn unknown<E: ToString>(error: E) -> Self {
Self::Unknown(error.to_string())
}
}
impl From<&str> for Error {
fn from(value: &str) -> Self {
Self::Unknown(String::from(value))
}
}
impl From<String> for Error {
fn from(value: String) -> Self {
Self::Unknown(value)
}
}
}