Expand description
The bitwise XOR operator ^
.
Note that Rhs
is Self
by default, but this is not mandatory.
An implementation of BitXor
that lifts ^
to a wrapper around bool
.
use std::ops::BitXor;
#[derive(Debug, PartialEq)]
struct Scalar(bool);
impl BitXor for Scalar {
type Output = Self;
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0 ^ rhs.0)
}
}
assert_eq!(Scalar(true) ^ Scalar(true), Scalar(false));
assert_eq!(Scalar(true) ^ Scalar(false), Scalar(true));
assert_eq!(Scalar(false) ^ Scalar(true), Scalar(true));
assert_eq!(Scalar(false) ^ Scalar(false), Scalar(false));
An implementation of BitXor
trait for a wrapper around Vec<bool>
.
use std::ops::BitXor;
#[derive(Debug, PartialEq)]
struct BooleanVector(Vec<bool>);
impl BitXor for BooleanVector {
type Output = Self;
fn bitxor(self, Self(rhs): Self) -> Self::Output {
let Self(lhs) = self;
assert_eq!(lhs.len(), rhs.len());
Self(
lhs.iter()
.zip(rhs.iter())
.map(|(x, y)| *x ^ *y)
.collect()
)
}
}
let bv1 = BooleanVector(vec![true, true, false, false]);
let bv2 = BooleanVector(vec![true, false, true, false]);
let expected = BooleanVector(vec![false, true, true, false]);
assert_eq!(bv1 ^ bv2, expected);
The resulting type after applying the ^
operator.
Performs the ^
operation.
assert_eq!(true ^ false, true);
assert_eq!(true ^ true, false);
assert_eq!(5u8 ^ 1u8, 4);
assert_eq!(5u8 ^ 2u8, 7);
impl<'_> BitXor<&'_ LittleEndian<i16>> for LittleEndian<i16>
impl<'_> BitXor<&'_ LittleEndian<i32>> for LittleEndian<i32>
impl<'_> BitXor<&'_ LittleEndian<i64>> for LittleEndian<i64>
impl<'_> BitXor<&'_ LittleEndian<u16>> for LittleEndian<u16>
impl<'_> BitXor<&'_ LittleEndian<u32>> for LittleEndian<u32>
impl<'_> BitXor<&'_ LittleEndian<u64>> for LittleEndian<u64>
impl<'_> BitXor<&'_ NativeEndian<i16>> for NativeEndian<i16>
impl<'_> BitXor<&'_ NativeEndian<i32>> for NativeEndian<i32>
impl<'_> BitXor<&'_ NativeEndian<i64>> for NativeEndian<i64>
impl<'_> BitXor<&'_ NativeEndian<u16>> for NativeEndian<u16>
impl<'_> BitXor<&'_ NativeEndian<u32>> for NativeEndian<u32>
impl<'_> BitXor<&'_ NativeEndian<u64>> for NativeEndian<u64>
impl<'_> BitXor<LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_> BitXor<LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_> BitXor<LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_> BitXor<LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_> BitXor<LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_> BitXor<LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_> BitXor<NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_> BitXor<NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_> BitXor<NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_> BitXor<NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_> BitXor<NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_> BitXor<NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_, '_> BitXor<&'_ BigEndian<i16>> for &'_ BigEndian<i16>
impl<'_, '_> BitXor<&'_ BigEndian<i32>> for &'_ BigEndian<i32>
impl<'_, '_> BitXor<&'_ BigEndian<i64>> for &'_ BigEndian<i64>
impl<'_, '_> BitXor<&'_ BigEndian<u16>> for &'_ BigEndian<u16>
impl<'_, '_> BitXor<&'_ BigEndian<u32>> for &'_ BigEndian<u32>
impl<'_, '_> BitXor<&'_ BigEndian<u64>> for &'_ BigEndian<u64>
impl<'_, '_> BitXor<&'_ LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_, '_> BitXor<&'_ LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_, '_> BitXor<&'_ LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_, '_> BitXor<&'_ LittleEndian<i128>> for &'_ LittleEndian<i128>
impl<'_, '_> BitXor<&'_ LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_, '_> BitXor<&'_ LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_, '_> BitXor<&'_ LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_, '_> BitXor<&'_ LittleEndian<u128>> for &'_ LittleEndian<u128>
impl<'_, '_> BitXor<&'_ NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_, '_> BitXor<&'_ NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_, '_> BitXor<&'_ NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_, '_> BitXor<&'_ NativeEndian<i128>> for &'_ NativeEndian<i128>
impl<'_, '_> BitXor<&'_ NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_, '_> BitXor<&'_ NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_, '_> BitXor<&'_ NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_, '_> BitXor<&'_ NativeEndian<u128>> for &'_ NativeEndian<u128>