concurrent_avl_tree 0.1.0

Lock-free readable AVL tree with epoch-based reclamation and background batch rebalancing.
Documentation
//! # Error Handling Strategy
//!
//! Custom error enumeration for library-specific failure modes.
//! Implements `std::fmt::Display` and `std::error::Error`.

use std::fmt;

/// # Library Error Enumeration
///
/// Represents recoverable failure conditions during tree operations or memory management.
///
/// ## Description
/// Centralized error type for the `concurrent-avl` crate. Categorized by failure origin:
/// allocation exhaustion or invalid configuration. Implements `Clone` and `Debug` for logging.
///
/// ## Invariant
/// `self` remains in a valid, inspectable state after construction.
///
/// ## Thread Safety
/// `Send + Sync`. Immutable references shareable across threads.
///
/// ## Performance
/// Stack-allocated. Zero dynamic memory usage. Trivially copyable.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConcurrentAVLError {
    /// Insufficient arena capacity for requested allocation.
    AllocationExhausted,
    /// Invalid batch operation or corrupted state detected.
    InvalidOperation(String),
}

impl fmt::Display for ConcurrentAVLError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::AllocationExhausted => write!(f, "Memory arena capacity exhausted"),
            Self::InvalidOperation(msg) => write!(f, "Invalid operation: {msg}"),
        }
    }
}

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

/// # Examples
/// ```
/// use concurrent_avl::error::ConcurrentAVLError;
///
/// let err = ConcurrentAVLError::InvalidOperation("capacity exceeded".into());
/// assert!(err.to_string().contains("capacity exceeded"));
/// ```
#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn verify_error_display() {
        assert_eq!(
            ConcurrentAVLError::AllocationExhausted.to_string(),
            "Memory arena capacity exhausted"
        );
    }
}