Skip to content

Commit

Permalink
Implement Debug manually for UnderfilledError
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickariel committed Dec 20, 2024
1 parent 09b6854 commit 921bebc
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<T> fmt::Debug for CapacityError<T> {
}

/// Error value indicating that capacity is not completely filled
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct UnderfilledError<T, const CAP: usize>(ArrayVec<T, CAP>);

impl<T, const CAP: usize> UnderfilledError<T, CAP> {
Expand All @@ -63,11 +63,27 @@ impl<T, const CAP: usize> UnderfilledError<T, CAP> {
}
}

impl<T, const CAP: usize> fmt::Debug for UnderfilledError<T, CAP> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"UnderfilledError: capacity is not filled: expected {}, got {}",
CAP,
self.0.len()
)
}
}

#[cfg(feature="std")]
impl<T: fmt::Debug, const CAP: usize> Error for UnderfilledError<T, CAP> {}
impl<T, const CAP: usize> Error for UnderfilledError<T, CAP> {}

impl<T, const CAP: usize> fmt::Display for UnderfilledError<T, CAP> {
impl<T, const CAP: usize> fmt::Display for UnderfilledError<T, CAP> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "capacity is not filled: expected {}, got {}", CAP, self.0.len())
write!(
f,
"capacity is not filled: expected {}, got {}",
CAP,
self.0.len()
)
}
}

0 comments on commit 921bebc

Please sign in to comment.