Expand description
The bitwise AND operator &
.
Note that Rhs
is Self
by default, but this is not mandatory.
An implementation of BitAnd
for a wrapper around bool
.
use std::ops::BitAnd;
#[derive(Debug, PartialEq)]
struct Scalar(bool);
impl BitAnd for Scalar {
type Output = Self;
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}
assert_eq!(Scalar(true) & Scalar(true), Scalar(true));
assert_eq!(Scalar(true) & Scalar(false), Scalar(false));
assert_eq!(Scalar(false) & Scalar(true), Scalar(false));
assert_eq!(Scalar(false) & Scalar(false), Scalar(false));
An implementation of BitAnd
for a wrapper around Vec<bool>
.
use std::ops::BitAnd;
#[derive(Debug, PartialEq)]
struct BooleanVector(Vec<bool>);
impl BitAnd for BooleanVector {
type Output = Self;
fn bitand(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![true, false, false, false]);
assert_eq!(bv1 & bv2, expected);
The resulting type after applying the &
operator.
Performs the &
operation.
assert_eq!(true & false, false);
assert_eq!(true & true, true);
assert_eq!(5u8 & 1u8, 1);
assert_eq!(5u8 & 2u8, 0);
impl<'_> BitAnd<&'_ LittleEndian<i16>> for LittleEndian<i16>
impl<'_> BitAnd<&'_ LittleEndian<i32>> for LittleEndian<i32>
impl<'_> BitAnd<&'_ LittleEndian<i64>> for LittleEndian<i64>
impl<'_> BitAnd<&'_ LittleEndian<u16>> for LittleEndian<u16>
impl<'_> BitAnd<&'_ LittleEndian<u32>> for LittleEndian<u32>
impl<'_> BitAnd<&'_ LittleEndian<u64>> for LittleEndian<u64>
impl<'_> BitAnd<&'_ NativeEndian<i16>> for NativeEndian<i16>
impl<'_> BitAnd<&'_ NativeEndian<i32>> for NativeEndian<i32>
impl<'_> BitAnd<&'_ NativeEndian<i64>> for NativeEndian<i64>
impl<'_> BitAnd<&'_ NativeEndian<u16>> for NativeEndian<u16>
impl<'_> BitAnd<&'_ NativeEndian<u32>> for NativeEndian<u32>
impl<'_> BitAnd<&'_ NativeEndian<u64>> for NativeEndian<u64>
impl<'_> BitAnd<LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_> BitAnd<LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_> BitAnd<LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_> BitAnd<LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_> BitAnd<LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_> BitAnd<LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_> BitAnd<NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_> BitAnd<NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_> BitAnd<NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_> BitAnd<NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_> BitAnd<NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_> BitAnd<NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_, '_> BitAnd<&'_ BigEndian<i16>> for &'_ BigEndian<i16>
impl<'_, '_> BitAnd<&'_ BigEndian<i32>> for &'_ BigEndian<i32>
impl<'_, '_> BitAnd<&'_ BigEndian<i64>> for &'_ BigEndian<i64>
impl<'_, '_> BitAnd<&'_ BigEndian<u16>> for &'_ BigEndian<u16>
impl<'_, '_> BitAnd<&'_ BigEndian<u32>> for &'_ BigEndian<u32>
impl<'_, '_> BitAnd<&'_ BigEndian<u64>> for &'_ BigEndian<u64>
impl<'_, '_> BitAnd<&'_ LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_, '_> BitAnd<&'_ LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_, '_> BitAnd<&'_ LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_, '_> BitAnd<&'_ LittleEndian<i128>> for &'_ LittleEndian<i128>
impl<'_, '_> BitAnd<&'_ LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_, '_> BitAnd<&'_ LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_, '_> BitAnd<&'_ LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_, '_> BitAnd<&'_ LittleEndian<u128>> for &'_ LittleEndian<u128>
impl<'_, '_> BitAnd<&'_ NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_, '_> BitAnd<&'_ NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_, '_> BitAnd<&'_ NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_, '_> BitAnd<&'_ NativeEndian<i128>> for &'_ NativeEndian<i128>
impl<'_, '_> BitAnd<&'_ NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_, '_> BitAnd<&'_ NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_, '_> BitAnd<&'_ NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_, '_> BitAnd<&'_ NativeEndian<u128>> for &'_ NativeEndian<u128>
impl<'_, '_, T, S, A> BitAnd<&'_ HashSet<T, S, A>> for &'_ HashSet<T, S, A> where
T: Eq + Hash + Clone,
S: BuildHasher + Default,
A: Allocator + Clone,
impl<'_, '_, T, S, A> BitAnd<&'_ HashSet<T, S, A>> for &'_ HashSet<T, S, A> where
T: Eq + Hash + Clone,
S: BuildHasher + Default,
A: Allocator + Clone,