inspect-core 0.1.0

Core types and traits for the inspect-rs introspection system
Documentation
//! Error types for inspection.

#[cfg(not(feature = "std"))]
use alloc::string::String;
use core::fmt;

/// Result type for inspection operations.
pub type InspectResult<T> = Result<T, InspectError>;

/// Errors that can occur during inspection.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InspectError {
    /// A configured limit was exceeded.
    LimitExceeded(String),

    /// The requested path does not exist.
    InvalidPath(String),

    /// The value kind does not support the requested operation.
    UnsupportedOperation(String),

    /// A cycle was detected in the value graph.
    CycleDetected,

    /// A custom error from a user implementation.
    Custom(String),
}

impl fmt::Display for InspectError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            InspectError::LimitExceeded(msg) => write!(f, "Limit exceeded: {}", msg),
            InspectError::InvalidPath(msg) => write!(f, "Invalid path: {}", msg),
            InspectError::UnsupportedOperation(msg) => {
                write!(f, "Unsupported operation: {}", msg)
            }
            InspectError::CycleDetected => write!(f, "Cycle detected"),
            InspectError::Custom(msg) => write!(f, "{}", msg),
        }
    }
}

#[cfg(feature = "std")]
impl std::error::Error for InspectError {}