use super::*;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Boolean(pub bool);
impl From<bool> for Boolean {
fn from(b: bool) -> Self { Self(b) }
}
impl From<Boolean> for bool {
fn from(b: Boolean) -> Self { b.0 }
}
impl One for Boolean {
fn one() -> Self { Self(true) }
}
impl Zero for Boolean {
fn zero() -> Self { Self(false) }
fn is_zero(&self) -> bool { !self.0 }
}
impl Add for Boolean {
type Output = Self;
#[allow(clippy::suspicious_arithmetic_impl)]
fn add(self, rhs: Self) -> Self::Output { Self(self.0 ^ rhs.0) }
}
impl Sub for Boolean {
type Output = Self;
#[allow(clippy::suspicious_arithmetic_impl)]
fn sub(self, rhs: Self) -> Self::Output { self + rhs }
}
impl Neg for Boolean {
type Output = Self;
fn neg(self) -> Self::Output { self }
}
impl SubAssign for Boolean {
#[allow(clippy::suspicious_op_assign_impl)]
fn sub_assign(&mut self, rhs: Self) { self.0 ^= rhs.0; }
}
impl AddAssign for Boolean {
#[allow(clippy::suspicious_op_assign_impl)]
fn add_assign(&mut self, rhs: Self) { self.0 ^= rhs.0; }
}
impl Mul for Boolean {
type Output = Self;
fn mul(self, rhs: Self) -> Self::Output { Self(self.0 && rhs.0) }
}
impl MulAssign for Boolean {
#[allow(clippy::suspicious_op_assign_impl)]
fn mul_assign(&mut self, rhs: Self) { self.0 &= rhs.0; }
}
impl Div for Boolean {
type Output = Self;
#[allow(clippy::suspicious_arithmetic_impl)]
fn div(self, rhs: Self) -> Self::Output { self * rhs }
}
impl DivAssign for Boolean {
#[allow(clippy::suspicious_op_assign_impl)]
fn div_assign(&mut self, rhs: Self) { self.0 &= rhs.0; }
}
impl Additive for Boolean {}
impl Multiplicative for Boolean {}
impl groups::Group for Boolean {
fn identity() -> Self { Self(false) }
fn inverse(&self) -> Self { Self(!self.0) }
}
impl groups::AbelianGroup for Boolean {}
impl rings::Ring for Boolean {}
impl rings::Field for Boolean {
fn multiplicative_inverse(&self) -> Self { *self }
}
impl modules::LeftModule for Boolean {
type Ring = Self;
}
impl modules::RightModule for Boolean {
type Ring = Self;
}
impl modules::TwoSidedModule for Boolean {
type Ring = Self;
}
impl modules::VectorSpace for Boolean {}