1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-08-02 05:08:31 +00:00
continuwuity/src/core/utils/math/expected.rs
Jason Volk 1a71798859 add Expected trait to utils; use (already transitive) num-traits.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-01-01 23:28:01 -05:00

52 lines
824 B
Rust

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 {}