xz-memory-core 0.2.0

Core abstractions for the xz-memory storage engine: EntryStore, IndexSearcher, and shared types
Documentation
use thiserror::Error;

/// Errors for entry store operations.
#[derive(Error, Debug)]
pub enum StoreError {
    /// The underlying storage backend returned an error.
    #[error("Storage backend error: {0}")]
    Backend(String),

    /// The requested entry was not found.
    #[error("Entry not found: {0}")]
    NotFound(String),

    /// Serialization or deserialization failure.
    #[error("Serialization error: {0}")]
    Serialization(String),

    /// Invalid configuration.
    #[error("Invalid configuration: {0}")]
    Config(String),
}

impl StoreError {
    /// Returns `true` if the operation can be safely retried.
    pub fn is_retryable(&self) -> bool {
        match self {
            StoreError::Backend(_) => true,
            StoreError::NotFound(_) => false,
            StoreError::Serialization(_) => false,
            StoreError::Config(_) => false,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_backend_is_retryable() {
        assert!(StoreError::Backend("transient".into()).is_retryable());
    }

    #[test]
    fn test_not_found_not_retryable() {
        assert!(!StoreError::NotFound("missing".into()).is_retryable());
    }

    #[test]
    fn test_debug_display() {
        let e = StoreError::Backend("db down".into());
        assert_eq!(format!("{}", e), "Storage backend error: db down");
    }
}