/*
    Appellation: error <module>
    Contrib: @FL03
*/

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

#[derive(Debug, thiserror::Error)]
pub enum MemoryError {
    #[error(transparent)]
    CoreError(#[from] eryon::Error),
    #[error(transparent)]
    Other(#[from] anyhow::Error),
    #[error("Unknown Error: {0}")]
    Unknown(String),
}

impl From<&str> for MemoryError {
    fn from(s: &str) -> Self {
        MemoryError::Unknown(s.to_string())
    }
}

impl From<String> for MemoryError {
    fn from(s: String) -> Self {
        MemoryError::Unknown(s)
    }
}

impl From<Box<dyn std::error::Error>> for MemoryError {
    fn from(e: Box<dyn std::error::Error>) -> Self {
        MemoryError::Unknown(e.to_string())
    }
}
