use crate::common::*; pub(crate) trait Invariant: Sized { fn invariant(self, invariant: D) -> Result; fn invariant_unwrap(self, invariant: D) -> T { #![allow(clippy::unwrap_used)] self.invariant(invariant).unwrap() } } impl Invariant for Option { fn invariant(self, invariant: D) -> Result { self.ok_or_else(|| Error::internal(format!("Invariant violated: {}", invariant))) } } impl Invariant for Result { fn invariant(self, invariant: D) -> Result { self.map_err(|err| Error::internal(format!("Invariant `{}` violated: {}", invariant, err))) } }