Files
tuwunel/src/core/utils/math/tried.rs
June Clementine Strawberry a1e1f40ded run cargo fix for rust 2024 changes and rustfmt
Signed-off-by: June Clementine Strawberry <strawberry@puppygock.gay>
2025-02-23 01:17:45 -05:00

48 lines
772 B
Rust

use num_traits::ops::checked::{CheckedAdd, CheckedDiv, CheckedMul, CheckedRem, CheckedSub};
use crate::{Result, checked};
pub trait Tried {
#[inline]
fn try_add(self, rhs: Self) -> Result<Self>
where
Self: CheckedAdd + Sized,
{
checked!(self + rhs)
}
#[inline]
fn try_sub(self, rhs: Self) -> Result<Self>
where
Self: CheckedSub + Sized,
{
checked!(self - rhs)
}
#[inline]
fn try_mul(self, rhs: Self) -> Result<Self>
where
Self: CheckedMul + Sized,
{
checked!(self * rhs)
}
#[inline]
fn try_div(self, rhs: Self) -> Result<Self>
where
Self: CheckedDiv + Sized,
{
checked!(self / rhs)
}
#[inline]
fn try_rem(self, rhs: Self) -> Result<Self>
where
Self: CheckedRem + Sized,
{
checked!(self % rhs)
}
}
impl<T> Tried for T {}