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));
Run
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);
Run
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);
Run
impl BitOr<&'_ bool> for &bool
impl BitOr<&'_ bool> for bool
impl BitOr<&'_ i8> for &i8
impl BitOr<&'_ i8> for i8
impl BitOr<&'_ i16> for &i16
impl BitOr<&'_ i16> for i16
impl BitOr<&'_ i32> for &i32
impl BitOr<&'_ i32> for i32
impl BitOr<&'_ i64> for &i64
impl BitOr<&'_ i64> for i64
impl BitOr<&'_ i128> for &i128
impl BitOr<&'_ i128> for i128
impl BitOr<&'_ isize> for &isize
impl BitOr<&'_ isize> for isize
impl BitOr<&'_ u8> for &u8
impl BitOr<&'_ u8> for u8
impl BitOr<&'_ u16> for &u16
impl BitOr<&'_ u16> for u16
impl BitOr<&'_ u32> for &u32
impl BitOr<&'_ u32> for u32
impl BitOr<&'_ u64> for &u64
impl BitOr<&'_ u64> for u64
impl BitOr<&'_ u128> for &u128
impl BitOr<&'_ u128> for u128
impl BitOr<&'_ usize> for &usize
impl BitOr<&'_ usize> for usize
impl BitOr<bool> for bool
impl BitOr<i128> for i128
impl BitOr<isize> for isize
impl BitOr<u128> for u128
impl BitOr<usize> for usize
impl<'a> BitOr<bool> for &'a bool
impl<'a> BitOr<i8> for &'a i8
impl<'a> BitOr<i16> for &'a i16
impl<'a> BitOr<i32> for &'a i32
impl<'a> BitOr<i64> for &'a i64
impl<'a> BitOr<i128> for &'a i128
impl<'a> BitOr<isize> for &'a isize
impl<'a> BitOr<u8> for &'a u8
impl<'a> BitOr<u16> for &'a u16
impl<'a> BitOr<u32> for &'a u32
impl<'a> BitOr<u64> for &'a u64
impl<'a> BitOr<u128> for &'a u128
impl<'a> BitOr<usize> for &'a usize