inspect-core 0.1.0

Core types and traits for the inspect-rs introspection system
Documentation
//! Inspection limits and safety constraints.

/// Limits to prevent pathological inspection behavior.
///
/// These limits protect against accidentally traversing enormous data
/// structures, infinite loops, or excessive memory allocation during
/// introspection.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InspectLimits {
    /// Maximum tree depth to traverse.
    pub max_depth: usize,

    /// Maximum number of items to inspect in a collection.
    pub max_items: usize,

    /// Maximum total number of nodes to visit.
    pub max_nodes: usize,

    /// Maximum length of a string to include.
    pub max_string_length: usize,

    /// Maximum number of bytes to include.
    pub max_bytes: usize,
}

impl InspectLimits {
    /// Create limits with all constraints set to maximum.
    pub const fn unlimited() -> Self {
        Self {
            max_depth: usize::MAX,
            max_items: usize::MAX,
            max_nodes: usize::MAX,
            max_string_length: usize::MAX,
            max_bytes: usize::MAX,
        }
    }

    /// Create limits suitable for interactive debugging.
    pub const fn debug() -> Self {
        Self {
            max_depth: 32,
            max_items: 100,
            max_nodes: 10_000,
            max_string_length: 1024,
            max_bytes: 4096,
        }
    }

    /// Create limits suitable for compact logging.
    pub const fn compact() -> Self {
        Self {
            max_depth: 8,
            max_items: 10,
            max_nodes: 1000,
            max_string_length: 128,
            max_bytes: 256,
        }
    }
}

impl Default for InspectLimits {
    fn default() -> Self {
        Self::debug()
    }
}