supercode_reduce/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct ReductionError {
8 message: String,
9}
10
11impl ReductionError {
12 pub fn new(message: impl Into<String>) -> Self {
14 Self {
15 message: message.into(),
16 }
17 }
18
19 pub fn message(&self) -> &str {
21 &self.message
22 }
23}
24
25impl fmt::Display for ReductionError {
26 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
27 formatter.write_str(&self.message)
28 }
29}
30
31impl std::error::Error for ReductionError {}
32
33pub type Result<T> = std::result::Result<T, ReductionError>;
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn display_is_the_stable_invariant_explanation() {
42 let error = ReductionError::new("sidecar hash mismatch");
43 assert_eq!(error.message(), "sidecar hash mismatch");
44 assert_eq!(error.to_string(), "sidecar hash mismatch");
45 }
46}