add Expected trait to utils; use (already transitive) num-traits.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk authored and strawberry committed 2025-01-01 23:28:01 -05:00
1 parent 7e4453620e
commit 1a71798859
5 files changed
+60

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
use num_traits::ops::checked::{CheckedAdd, CheckedDiv, CheckedMul, CheckedRem, CheckedSub};
use crate::expected;
pub trait Expected {
#[inline]
#[must_use]
fn expected_add(self, rhs: Self) -> Self
where
Self: CheckedAdd + Sized,
{
expected!(self + rhs)
}
#[inline]
#[must_use]
fn expected_sub(self, rhs: Self) -> Self
where
Self: CheckedSub + Sized,
{
expected!(self - rhs)
}
#[inline]
#[must_use]
fn expected_mul(self, rhs: Self) -> Self
where
Self: CheckedMul + Sized,
{
expected!(self * rhs)
}
#[inline]
#[must_use]
fn expected_div(self, rhs: Self) -> Self
where
Self: CheckedDiv + Sized,
{
expected!(self / rhs)
}
#[inline]
#[must_use]
fn expected_rem(self, rhs: Self) -> Self
where
Self: CheckedRem + Sized,
{
expected!(self % rhs)
}
}
impl<T> Expected for T {}