reth_primitives_traits/
error.rsuse alloc::boxed::Box;
use core::{
fmt,
ops::{Deref, DerefMut},
};
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct GotExpected<T> {
pub got: T,
pub expected: T,
}
impl<T: fmt::Display> fmt::Display for GotExpected<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "got {}, expected {}", self.got, self.expected)
}
}
impl<T: fmt::Debug + fmt::Display> core::error::Error for GotExpected<T> {}
impl<T> From<(T, T)> for GotExpected<T> {
#[inline]
fn from((got, expected): (T, T)) -> Self {
Self::new(got, expected)
}
}
impl<T> GotExpected<T> {
#[inline]
pub const fn new(got: T, expected: T) -> Self {
Self { got, expected }
}
}
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct GotExpectedBoxed<T>(pub Box<GotExpected<T>>);
impl<T: fmt::Debug> fmt::Debug for GotExpectedBoxed<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl<T: fmt::Display> fmt::Display for GotExpectedBoxed<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl<T: fmt::Debug + fmt::Display> core::error::Error for GotExpectedBoxed<T> {}
impl<T> Deref for GotExpectedBoxed<T> {
type Target = GotExpected<T>;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> DerefMut for GotExpectedBoxed<T> {
#[inline(always)]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<T> From<(T, T)> for GotExpectedBoxed<T> {
#[inline]
fn from(value: (T, T)) -> Self {
Self(Box::new(GotExpected::from(value)))
}
}
impl<T> From<GotExpected<T>> for GotExpectedBoxed<T> {
#[inline]
fn from(value: GotExpected<T>) -> Self {
Self(Box::new(value))
}
}