thingd-core 0.26.0

Core primitives for thingd, an object-shaped local memory engine for apps and agents.
Documentation
//! Error types for thingd core operations.

use std::error::Error;
use std::fmt::{Display, Formatter, Result as FormatResult};

/// Result type returned by thingd core operations.
pub type ThingdResult<T> = Result<T, ThingdError>;

/// Error type returned by thingd core operations.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ThingdError {
    /// The caller provided invalid input.
    InvalidInput(String),
    /// A requested record could not be found.
    NotFound(String),
    /// The requested operation conflicts with current state.
    Conflict(String),
    /// The storage adapter failed.
    Storage(String),
}

impl Display for ThingdError {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> FormatResult {
        match self {
            Self::InvalidInput(message) => write!(formatter, "invalid input: {message}"),
            Self::NotFound(message) => write!(formatter, "not found: {message}"),
            Self::Conflict(message) => write!(formatter, "conflict: {message}"),
            Self::Storage(message) => write!(formatter, "storage error: {message}"),
        }
    }
}

impl Error for ThingdError {}

#[cfg(feature = "sqlite")]
impl From<rusqlite::Error> for ThingdError {
    fn from(error: rusqlite::Error) -> Self {
        Self::Storage(error.to_string())
    }
}