pub trait BitOr<Rhs = Self> {
type Output;
// Required method
fn bitor(self, rhs: Rhs) -> Self::Output;
}Expand description
∧
core
The bitwise OR operator |.
📍code/ops re-exported from core::ops
📜
The bitwise OR operator |.
Note that Rhs is Self by default, but this is not mandatory.
§Examples
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;
// rhs is the "right-hand side" of the expression `a | b`
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);Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl BitOr for AppControlSet
impl BitOr for AppControlSet
type Output = AppControlSet
Source§impl BitOr for EnumSetExample
Available on doc or test only.
impl BitOr for EnumSetExample
Available on
doc or test only.type Output = EnumSetExample
Source§impl BitOr for EventButtons
Available on crate feature event only.
impl BitOr for EventButtons
Available on crate feature
event only.type Output = EventButtons
Source§impl BitOr for EventTagSet
Available on crate feature event only.
impl BitOr for EventTagSet
Available on crate feature
event only.type Output = EventTagSet
Source§impl BitOr for LinuxSigactionFlags
Available on crate feature linux only.
impl BitOr for LinuxSigactionFlags
Available on crate feature
linux only.type Output = LinuxSigactionFlags
Source§impl BitOr for LinuxSignalSet
Available on crate feature linux only.
impl BitOr for LinuxSignalSet
Available on crate feature
linux only.type Output = LinuxSignalSet
Source§impl BitOr for LinuxTermiosControlFlags
Available on crate feature linux only.
impl BitOr for LinuxTermiosControlFlags
Available on crate feature
linux only.Source§impl BitOr for LinuxTermiosInputFlags
Available on crate feature linux only.
impl BitOr for LinuxTermiosInputFlags
Available on crate feature
linux only.Source§impl BitOr for LinuxTermiosLocalFlags
Available on crate feature linux only.
impl BitOr for LinuxTermiosLocalFlags
Available on crate feature
linux only.Source§impl BitOr for LinuxTermiosOutputFlags
Available on crate feature linux only.
impl BitOr for LinuxTermiosOutputFlags
Available on crate feature
linux only.Source§impl BitOr for RandQualities
impl BitOr for RandQualities
type Output = RandQualities
Source§impl BitOr for RunCapInput
impl BitOr for RunCapInput
type Output = RunCapInput
Source§impl BitOr for RunCapSystem
impl BitOr for RunCapSystem
type Output = RunCapSystem
Source§impl BitOr for RunCapText
impl BitOr for RunCapText
type Output = RunCapText
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<i16>
impl BitOr for Saturating<i16>
type Output = Saturating<i16>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<i32>
impl BitOr for Saturating<i32>
type Output = Saturating<i32>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<i64>
impl BitOr for Saturating<i64>
type Output = Saturating<i64>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<i128>
impl BitOr for Saturating<i128>
type Output = Saturating<i128>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<isize>
impl BitOr for Saturating<isize>
type Output = Saturating<isize>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<u16>
impl BitOr for Saturating<u16>
type Output = Saturating<u16>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<u32>
impl BitOr for Saturating<u32>
type Output = Saturating<u32>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<u64>
impl BitOr for Saturating<u64>
type Output = Saturating<u64>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<u128>
impl BitOr for Saturating<u128>
type Output = Saturating<u128>
1.74.0 (const: unstable) · Source§impl BitOr for Saturating<usize>
impl BitOr for Saturating<usize>
type Output = Saturating<usize>
Source§impl BitOr for TermStyleExt
Available on crate feature term only.
impl BitOr for TermStyleExt
Available on crate feature
term only.