use alloc::boxed::Box; use core::ops::{Deref, DerefMut}; /// A pair of values, one of which is expected and one of which is actual. #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, thiserror::Error)] #[error("got {got}, expected {expected}")] pub struct GotExpected { /// The actual value. pub got: T, /// The expected value. pub expected: T, } impl From<(T, T)> for GotExpected { #[inline] fn from((got, expected): (T, T)) -> Self { Self::new(got, expected) } } impl GotExpected { /// Creates a new error from a pair of values. #[inline] pub const fn new(got: T, expected: T) -> Self { Self { got, expected } } } /// A pair of values, one of which is expected and one of which is actual. /// /// Same as [`GotExpected`], but [`Box`]ed for smaller size. /// /// Prefer instantiating using [`GotExpected`], and then using `.into()` to convert to this type. #[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, thiserror::Error, Debug)] #[error(transparent)] pub struct GotExpectedBoxed(pub Box>); impl Deref for GotExpectedBoxed { type Target = GotExpected; #[inline(always)] fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for GotExpectedBoxed { #[inline(always)] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl From<(T, T)> for GotExpectedBoxed { #[inline] fn from(value: (T, T)) -> Self { Self(Box::new(GotExpected::from(value))) } } impl From> for GotExpectedBoxed { #[inline] fn from(value: GotExpected) -> Self { Self(Box::new(value)) } }