Add debug assertion

This commit is contained in:
Christian Duerr 2021-11-22 00:24:16 +01:00 committed by Victor Berger
parent d46be20d6e
commit 0d2c3acdc7
1 changed files with 9 additions and 2 deletions

View File

@ -18,7 +18,7 @@ pub struct Buffer;
pub struct Raw;
pub trait Coordinate:
Sized + Add<Self, Output = Self> + Sub<Self, Output = Self> + PartialOrd + Default + Copy + std::fmt::Debug
Sized + Add<Self, Output = Self> + Sub<Self, Output = Self> + PartialOrd + Default + Copy + fmt::Debug
{
fn downscale(self, scale: Self) -> Self;
fn upscale(self, scale: Self) -> Self;
@ -637,9 +637,16 @@ impl<N: AddAssign, Kind> AddAssign for Size<N, Kind> {
}
}
impl<N: SubAssign, Kind> SubAssign for Size<N, Kind> {
impl<N: SubAssign + fmt::Debug + PartialOrd, Kind> SubAssign for Size<N, Kind> {
#[inline]
fn sub_assign(&mut self, rhs: Self) {
debug_assert!(
self.w >= rhs.w && self.h >= rhs.h,
"Attempting to subtract bigger from smaller size: {:?} - {:?}",
(&self.w, &self.h),
(&rhs.w, &rhs.h),
);
self.w -= rhs.w;
self.h -= rhs.h
}