cotyledon 0.1.0

Framework for writing sprouts — sandboxed, event-driven on-chain trading bots.
Documentation
//! Error type returned by sprout handlers.

use std::fmt;

/// Convenience alias — handlers return `Result<()>`.
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// A sprout error.
#[derive(Debug)]
pub enum Error {
    /// A first-class call to the engine failed.
    Host(String),
    /// (De)serializing config or an event payload failed.
    Codec(String),
    /// A guardrail or policy rejected the operation.
    Denied(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Host(m) => write!(f, "host error: {m}"),
            Error::Codec(m) => write!(f, "codec error: {m}"),
            Error::Denied(m) => write!(f, "denied: {m}"),
        }
    }
}

impl std::error::Error for Error {}

impl From<serde_json::Error> for Error {
    fn from(err: serde_json::Error) -> Self {
        Error::Codec(err.to_string())
    }
}