#[allow(unused)]
use core::ops::{
Neg,
Add, AddAssign, Sub, SubAssign,
Mul, MulAssign, Div, DivAssign, Rem, RemAssign
};
pub trait TryNeg {
type Error;
type Output;
fn try_neg(self) -> Result<Self::Output, Self::Error>;
}
pub trait TryAdd<Rhs = Self> {
type Error;
type Output;
fn try_add(self, other: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TrySub<Rhs = Self> {
type Error;
type Output;
fn try_sub(self, other: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryMul<Rhs = Self> {
type Error;
type Output;
fn try_mul(self, other: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryDiv<Rhs = Self> {
type Error;
type Output;
fn try_div(self, other: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryRem<Rhs = Self> {
type Error;
type Output;
fn try_rem(self, other: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryAddAssign<Rhs = Self> {
type Error;
fn try_add_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
}
pub trait TrySubAssign<Rhs = Self> {
type Error;
fn try_sub_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
}
pub trait TryMulAssign<Rhs = Self> {
type Error;
fn try_mul_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
}
pub trait TryDivAssign<Rhs = Self> {
type Error;
fn try_div_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
}
pub trait TryRemAssign<Rhs = Self> {
type Error;
fn try_rem_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
}
impl<T: Add<Rhs>, Rhs> TryAdd<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Add<Rhs>>::Output;
#[inline]
fn try_add(self, other: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self + other)
}
}
impl<T: Sub<Rhs>, Rhs> TrySub<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Sub<Rhs>>::Output;
#[inline]
fn try_sub(self, other: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self - other)
}
}
impl<T: Mul<Rhs>, Rhs> TryMul<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Mul<Rhs>>::Output;
#[inline]
fn try_mul(self, other: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self * other)
}
}
impl<T: Div<Rhs>, Rhs> TryDiv<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Div<Rhs>>::Output;
#[inline]
fn try_div(self, other: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self / other)
}
}
impl<T: Rem<Rhs>, Rhs> TryRem<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Rem<Rhs>>::Output;
#[inline]
fn try_rem(self, other: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self % other)
}
}
impl<T: AddAssign<Rhs>, Rhs> TryAddAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_add_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
Ok(self.add_assign(other))
}
}
impl<T: SubAssign<Rhs>, Rhs> TrySubAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_sub_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
Ok(self.sub_assign(other))
}
}
impl<T: MulAssign<Rhs>, Rhs> TryMulAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_mul_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
Ok(self.mul_assign(other))
}
}
impl<T: DivAssign<Rhs>, Rhs> TryDivAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_div_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
Ok(self.div_assign(other))
}
}
impl<T: RemAssign<Rhs>, Rhs> TryRemAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_rem_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
Ok(self.rem_assign(other))
}
}