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