use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReductionError {
message: String,
}
impl ReductionError {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
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 {}
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");
}
}