acme_engine/
error.rs

1/*
2    appellation: error <module>
3    authors: @FL03
4*/
5//! this module defines the [`EngineError`] type to enumerate the various errors that can occur
6//! within the engine.
7
8#[allow(dead_code)]
9/// a type alias for a [`Result`](core::result::Result) that uses the[`EngineError`]
10pub(crate) type Result<T = ()> = core::result::Result<T, EngineError>;
11
12#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum EngineError {
15    #[cfg(feature = "alloc")]
16    #[error("Invalid operation: {0}")]
17    InvalidOperation(String),
18    #[error(transparent)]
19    CoreError(#[from] acme_core::error::Error),
20}
21
22#[cfg(feature = "alloc")]
23impl From<EngineError> for acme_core::error::Error {
24    fn from(err: EngineError) -> Self {
25        match err {
26            EngineError::CoreError(e) => e,
27            _ => acme_core::error::Error::box_error(err),
28        }
29    }
30}
31
32#[cfg(feature = "alloc")]
33impl From<String> for EngineError {
34    fn from(value: String) -> Self {
35        acme_core::Error::unknown(value).into()
36    }
37}
38
39#[cfg(feature = "alloc")]
40impl From<&str> for EngineError {
41    fn from(value: &str) -> Self {
42        acme_core::Error::unknown(value).into()
43    }
44}