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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
824 B
Rust
Raw Normal View History

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