reqsketch 0.2.0

Relative Error Quantiles sketch
Documentation
//! Error types for the REQ sketch library.

use std::fmt;

/// Result type alias for REQ sketch operations.
pub type Result<T> = std::result::Result<T, ReqError>;

/// Error types that can occur during REQ sketch operations.
#[derive(Debug, Clone, PartialEq)]
pub enum ReqError {
    /// The sketch is empty and cannot perform the requested operation.
    EmptySketch,

    /// Invalid parameter k - must be even and in the range [4, 1024].
    InvalidK(u16),

    /// Invalid rank - must be in range [0.0, 1.0].
    InvalidRank(f64),

    /// Query item is NaN, which has no meaningful rank.
    NanItem,

    /// Incompatible sketches for merge operation.
    IncompatibleSketches(String),

    /// Split points are not properly sorted or contain invalid values.
    InvalidSplitPoints(String),
}

impl fmt::Display for ReqError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ReqError::EmptySketch => write!(f, "Cannot perform operation on empty sketch"),
            ReqError::InvalidK(k) => write!(
                f,
                "Invalid k parameter: {}. Must be even and in the range [4, 1024]",
                k
            ),
            ReqError::InvalidRank(rank) => {
                write!(f, "Invalid rank: {}. Must be in range [0.0, 1.0]", rank)
            }
            ReqError::NanItem => write!(f, "Query item is NaN"),
            ReqError::IncompatibleSketches(msg) => write!(f, "Incompatible sketches: {}", msg),
            ReqError::InvalidSplitPoints(msg) => write!(f, "Invalid split points: {}", msg),
        }
    }
}

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