supercode-reduce 0.4.9

Optional lossless, reversible session reduction for Supercode
Documentation
//! Errors raised by reversible projection, verification, and rehydration.

use std::fmt;

/// A reduction invariant failed or a reversible pointer could not be resolved.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReductionError {
    message: String,
}

impl ReductionError {
    /// Build an error with a stable, user-facing explanation.
    pub fn new(message: impl Into<String>) -> Self {
        Self {
            message: message.into(),
        }
    }

    /// Return the invariant failure explanation.
    pub fn message(&self) -> &str {
        &self.message
    }
}

impl fmt::Display for ReductionError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str(&self.message)
    }
}

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

/// Result type for standalone reduction operations.
pub type Result<T> = std::result::Result<T, ReductionError>;

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

    #[test]
    fn display_is_the_stable_invariant_explanation() {
        let error = ReductionError::new("sidecar hash mismatch");
        assert_eq!(error.message(), "sidecar hash mismatch");
        assert_eq!(error.to_string(), "sidecar hash mismatch");
    }
}