use core::ops::{Sub, Not, BitAnd, BitOr, BitXor, BitAndAssign, BitOrAssign, BitXorAssign, SubAssign, Add, AddAssign};
use crate::{ReprEnum, ESet};
impl<T: ReprEnum, const S: char> Not for ESet<T, S> {
type Output = ESet<T>;
fn not(self) -> Self::Output {
ESet(!self.0)
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> BitAnd<R> for ESet<T, S> {
type Output = ESet<T>;
fn bitand(self, rhs: R) -> Self::Output {
ESet(self.0 & rhs.into().0)
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> BitOr<R> for ESet<T, S> {
type Output = ESet<T>;
fn bitor(self, rhs: R) -> Self::Output {
ESet(self.0 | rhs.into().0)
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> BitXor<R> for ESet<T, S> {
type Output = ESet<T>;
fn bitxor(self, rhs: R) -> Self::Output {
ESet(self.0 ^ rhs.into().0)
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> Add<R> for ESet<T, S> {
type Output = ESet<T>;
fn add(self, rhs: R) -> Self::Output {
ESet(self.0 | rhs.into().0)
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> Sub<R> for ESet<T, S> {
type Output = ESet<T>;
fn sub(self, rhs: R) -> Self::Output {
ESet(self.0 ^ (self.0 & rhs.into().0))
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> BitAndAssign<R> for ESet<T, S> {
fn bitand_assign(&mut self, rhs: R) {
self.0 &= rhs.into().0;
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> BitOrAssign<R> for ESet<T, S> {
fn bitor_assign(&mut self, rhs: R) {
self.0 |= rhs.into().0;
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> BitXorAssign<R> for ESet<T, S> {
fn bitxor_assign(&mut self, rhs: R) {
self.0 ^= rhs.into().0;
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> AddAssign<R> for ESet<T, S> {
fn add_assign(&mut self, rhs: R) {
self.0 |= rhs.into().0;
}
}
impl<T: ReprEnum, R: Into<Self>, const S: char> SubAssign<R> for ESet<T, S> {
fn sub_assign(&mut self, rhs: R) {
self.0 ^= self.0 & rhs.into().0 ;
}
}
impl<T: ReprEnum, const S: char> PartialEq for ESet<T, S> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl<T: ReprEnum, const S: char> PartialOrd for ESet<T, S> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
if self.0 == other.0 {
Some(core::cmp::Ordering::Equal)
} else if self.0 & other.0 == other.0 {
Some(core::cmp::Ordering::Greater)
} else if self.0 & other.0 == self.0 {
Some(core::cmp::Ordering::Less)
} else {
None
}
}
}