eryon-core 0.0.3

The core modules of the eryon framework, providing essential functionality for computational entities.
Documentation
/*
    Appellation: error <module>
    Contrib: @FL03
*/
#[cfg(feature = "alloc")]
use alloc::{boxed::Box, string::String};

/// A type alias for a [`Result`](core::result::Result) with a custom error type ([Error])
pub type Result<T = ()> = core::result::Result<T, Error>;

/// The [`Error`] type enumerates the core errors that are handled by the framework
#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("Invalid Critical Point")]
    InvalidCriticalPoint,
    #[error("Invalid Operation")]
    InvalidOperation,
    #[error("Invalid Parameter")]
    InvalidParameter,
    #[error("Infinite loop detected")]
    InfiniteLoop,
    #[error("Lock Error")]
    LockError,
    #[error("Node not found")]
    NodeNotFound,
    #[error("Transformation Error")]
    TransformationError,
    #[cfg(feature = "alloc")]
    #[error("Driver Error: {0}")]
    DriverError(String),
    #[cfg(feature = "alloc")]
    #[error("Invalid State: {0}")]
    InvalidState(String),
    #[cfg(feature = "alloc")]
    #[error("Invalid Symbol: {0}")]
    InvalidSymbol(String),
    #[cfg(feature = "alloc")]
    #[error("Generative Error: {0}")]
    GenerativeError(String),
    #[cfg(feature = "alloc")]
    #[error("Parse Error: {0}")]
    ParseError(String),
    #[error(transparent)]
    MusicError(#[from] rstmt::Error),
    #[error(transparent)]
    TriadError(#[from] rstmt::nrt::TriadError),
    #[cfg(feature = "anyhow")]
    #[error(transparent)]
    AnyError(#[from] anyhow::Error),
    #[cfg(feature = "alloc")]
    #[error(transparent)]
    BoxError(#[from] Box<dyn core::error::Error + Send + Sync>),
    #[cfg(feature = "serde")]
    #[error(transparent)]
    DeserializeError(#[from] serde::de::value::Error),
    #[error(transparent)]
    FmtError(#[from] core::fmt::Error),
    #[error(transparent)]
    GraphError(#[from] rshyper::Error),
    #[cfg(feature = "std")]
    #[error(transparent)]
    IOError(#[from] std::io::Error),
    #[cfg(feature = "json")]
    #[error(transparent)]
    JsonError(#[from] serde_json::Error),
    #[error("Unknown Error: {0}")]
    Unknown(String),
}

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

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

#[cfg(feature = "std")]
impl<E> From<std::sync::PoisonError<E>> for Error {
    fn from(_: std::sync::PoisonError<E>) -> Self {
        Error::LockError
    }
}

#[cfg(feature = "std")]
impl<E> From<std::sync::TryLockError<E>> for Error {
    fn from(_: std::sync::TryLockError<E>) -> Self {
        Error::LockError
    }
}