Trait gstd::prelude::ops::BitOrAssign
1.8.0 · source · pub trait BitOrAssign<Rhs = Self> {
// Required method
fn bitor_assign(&mut self, rhs: Rhs);
}
Expand description
The bitwise OR assignment operator |=
.
§Examples
use std::ops::BitOrAssign;
#[derive(Debug, PartialEq)]
struct PersonalPreferences {
likes_cats: bool,
likes_dogs: bool,
}
impl BitOrAssign for PersonalPreferences {
fn bitor_assign(&mut self, rhs: Self) {
self.likes_cats |= rhs.likes_cats;
self.likes_dogs |= rhs.likes_dogs;
}
}
let mut prefs = PersonalPreferences { likes_cats: true, likes_dogs: false };
prefs |= PersonalPreferences { likes_cats: false, likes_dogs: true };
assert_eq!(prefs, PersonalPreferences { likes_cats: true, likes_dogs: true });
Required Methods§
1.8.0 · sourcefn bitor_assign(&mut self, rhs: Rhs)
fn bitor_assign(&mut self, rhs: Rhs)
Performs the |=
operation.
§Examples
let mut x = true;
x |= false;
assert_eq!(x, true);
let mut x = false;
x |= false;
assert_eq!(x, false);
let mut x: u8 = 5;
x |= 1;
assert_eq!(x, 5);
let mut x: u8 = 5;
x |= 2;
assert_eq!(x, 7);