eryon-mem 0.0.4

this crate implements the memory-related aspects of the eryon framework
/*
    Appellation: error <module>
    Contrib: @FL03
*/

/// a type alias for a [Result] equipped with a [MemoryError]
pub(crate) type Result<T> = core::result::Result<T, MemoryError>;

/// The [`MemoryError`] implementation enumerates the various errors handled by the memory
/// module.
#[derive(Debug, thiserror::Error)]
pub enum MemoryError {
    #[error(transparent)]
    CoreError(#[from] eryon::Error),
    #[cfg(feature = "serde")]
    #[error(transparent)]
    DeserializeError(#[from] serde::de::value::Error),
    #[error(transparent)]
    FmtError(#[from] core::fmt::Error),
    #[cfg(feature = "std")]
    #[error(transparent)]
    IOError(#[from] std::io::Error),
    #[cfg(feature = "serde_json")]
    #[error(transparent)]
    JsonError(#[from] serde_json::Error),
}
// #[cfg(feature = "alloc")]
impl From<MemoryError> for eryon::Error {
    fn from(err: MemoryError) -> Self {
        match err {
            MemoryError::CoreError(e) => e,
            _ => eryon::Error::BoxError(Box::new(err)),
        }
    }
}

#[cfg(feature = "std")]
impl From<&str> for MemoryError {
    fn from(s: &str) -> Self {
        eryon::Error::from(s).into()
    }
}

#[cfg(feature = "std")]
impl From<String> for MemoryError {
    fn from(s: String) -> Self {
        eryon::Error::from(s).into()
    }
}