#[allow(unused)]
use core::ops::{
Not,
BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign,
Shl, ShlAssign, Shr, ShrAssign
};
pub trait TryNot {
type Error;
type Output;
fn try_not(self) -> Result<Self::Output, Self::Error>;
}
pub trait TryBitAnd<Rhs = Self> {
type Error;
type Output;
fn try_bitand(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryBitOr<Rhs = Self> {
type Error;
type Output;
fn try_bitor(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryBitXor<Rhs = Self> {
type Error;
type Output;
fn try_bitxor(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryShl<Rhs = Self> {
type Error;
type Output;
fn try_shl(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryShr<Rhs = Self> {
type Error;
type Output;
fn try_shr(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
}
pub trait TryBitAndAssign<Rhs = Self> {
type Error;
fn try_bitand_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
}
pub trait TryBitOrAssign<Rhs = Self> {
type Error;
fn try_bitor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
}
pub trait TryBitXorAssign<Rhs = Self> {
type Error;
fn try_bitxor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
}
pub trait TryShlAssign<Rhs = Self> {
type Error;
fn try_shl_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
}
pub trait TryShrAssign<Rhs = Self> {
type Error;
fn try_shr_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
}
impl<T: Not> TryNot for T {
type Error = crate::Infallible;
type Output = <Self as Not>::Output;
#[inline]
fn try_not(self) -> Result<Self::Output, Self::Error> {
Ok(!self)
}
}
impl<T: BitAnd<Rhs>, Rhs> TryBitAnd<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as BitAnd<Rhs>>::Output;
#[inline]
fn try_bitand(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self & rhs)
}
}
impl<T: BitOr<Rhs>, Rhs> TryBitOr<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as BitOr<Rhs>>::Output;
#[inline]
fn try_bitor(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self | rhs)
}
}
impl<T: BitXor<Rhs>, Rhs> TryBitXor<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as BitXor<Rhs>>::Output;
#[inline]
fn try_bitxor(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self ^ rhs)
}
}
impl<T: Shl<Rhs>, Rhs> TryShl<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Shl<Rhs>>::Output;
#[inline]
fn try_shl(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self << rhs)
}
}
impl<T: Shr<Rhs>, Rhs> TryShr<Rhs> for T {
type Error = crate::Infallible;
type Output = <Self as Shr<Rhs>>::Output;
#[inline]
fn try_shr(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
Ok(self >> rhs)
}
}
impl<T: BitAndAssign<Rhs>, Rhs> TryBitAndAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_bitand_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
Ok(self.bitand_assign(rhs))
}
}
impl<T: BitOrAssign<Rhs>, Rhs> TryBitOrAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_bitor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
Ok(self.bitor_assign(rhs))
}
}
impl<T: BitXorAssign<Rhs>, Rhs> TryBitXorAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_bitxor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
Ok(self.bitxor_assign(rhs))
}
}
impl<T: ShlAssign<Rhs>, Rhs> TryShlAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_shl_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
Ok(self.shl_assign(rhs))
}
}
impl<T: ShrAssign<Rhs>, Rhs> TryShrAssign<Rhs> for T {
type Error = crate::Infallible;
#[inline]
fn try_shr_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
Ok(self.shr_assign(rhs))
}
}