Trait scale_info::prelude::ops::BitOrAssign
1.8.0 · source · [−]pub trait BitOrAssign<Rhs = Self> {
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
fn 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);
Implementations on Foreign Types
sourceimpl<T, const LANES: usize> BitOrAssign<Mask<T, LANES>> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> BitOrAssign<Mask<T, LANES>> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
fn bitor_assign(&mut self, rhs: Mask<T, LANES>)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ i8> for i8
impl<'_> BitOrAssign<&'_ i8> for i8
fn bitor_assign(&mut self, other: &i8)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ bool> for bool
impl<'_> BitOrAssign<&'_ bool> for bool
fn bitor_assign(&mut self, other: &bool)
const: unstable · sourceimpl BitOrAssign<i32> for i32
impl BitOrAssign<i32> for i32
fn bitor_assign(&mut self, other: i32)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ u128> for u128
impl<'_> BitOrAssign<&'_ u128> for u128
fn bitor_assign(&mut self, other: &u128)
const: unstable · sourceimpl BitOrAssign<usize> for usize
impl BitOrAssign<usize> for usize
fn bitor_assign(&mut self, other: usize)
const: unstable · sourceimpl BitOrAssign<i16> for i16
impl BitOrAssign<i16> for i16
fn bitor_assign(&mut self, other: i16)
const: unstable · sourceimpl BitOrAssign<i8> for i8
impl BitOrAssign<i8> for i8
fn bitor_assign(&mut self, other: i8)
sourceimpl<T, U, const LANES: usize> BitOrAssign<U> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: BitOr<U>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as BitOr<U>>::Output == Simd<T, LANES>,
impl<T, U, const LANES: usize> BitOrAssign<U> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: BitOr<U>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as BitOr<U>>::Output == Simd<T, LANES>,
fn bitor_assign(&mut self, rhs: U)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ i64> for i64
impl<'_> BitOrAssign<&'_ i64> for i64
fn bitor_assign(&mut self, other: &i64)
const: unstable · sourceimpl BitOrAssign<i128> for i128
impl BitOrAssign<i128> for i128
fn bitor_assign(&mut self, other: i128)
const: unstable · sourceimpl BitOrAssign<i64> for i64
impl BitOrAssign<i64> for i64
fn bitor_assign(&mut self, other: i64)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ i16> for i16
impl<'_> BitOrAssign<&'_ i16> for i16
fn bitor_assign(&mut self, other: &i16)
const: unstable · sourceimpl BitOrAssign<bool> for bool
impl BitOrAssign<bool> for bool
fn bitor_assign(&mut self, other: bool)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ isize> for isize
impl<'_> BitOrAssign<&'_ isize> for isize
fn bitor_assign(&mut self, other: &isize)
const: unstable · sourceimpl BitOrAssign<u128> for u128
impl BitOrAssign<u128> for u128
fn bitor_assign(&mut self, other: u128)
const: unstable · sourceimpl BitOrAssign<u8> for u8
impl BitOrAssign<u8> for u8
fn bitor_assign(&mut self, other: u8)
const: unstable · sourceimpl BitOrAssign<u64> for u64
impl BitOrAssign<u64> for u64
fn bitor_assign(&mut self, other: u64)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ usize> for usize
impl<'_> BitOrAssign<&'_ usize> for usize
fn bitor_assign(&mut self, other: &usize)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ i32> for i32
impl<'_> BitOrAssign<&'_ i32> for i32
fn bitor_assign(&mut self, other: &i32)
const: unstable · sourceimpl BitOrAssign<u32> for u32
impl BitOrAssign<u32> for u32
fn bitor_assign(&mut self, other: u32)
const: unstable · sourceimpl BitOrAssign<u16> for u16
impl BitOrAssign<u16> for u16
fn bitor_assign(&mut self, other: u16)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ u16> for u16
impl<'_> BitOrAssign<&'_ u16> for u16
fn bitor_assign(&mut self, other: &u16)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ i128> for i128
impl<'_> BitOrAssign<&'_ i128> for i128
fn bitor_assign(&mut self, other: &i128)
const: unstable · sourceimpl BitOrAssign<isize> for isize
impl BitOrAssign<isize> for isize
fn bitor_assign(&mut self, other: isize)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ u32> for u32
impl<'_> BitOrAssign<&'_ u32> for u32
fn bitor_assign(&mut self, other: &u32)
sourceimpl<T, const LANES: usize> BitOrAssign<bool> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> BitOrAssign<bool> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
fn bitor_assign(&mut self, rhs: bool)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ u64> for u64
impl<'_> BitOrAssign<&'_ u64> for u64
fn bitor_assign(&mut self, other: &u64)
1.22.0 (const: unstable) · sourceimpl<'_> BitOrAssign<&'_ u8> for u8
impl<'_> BitOrAssign<&'_ u8> for u8
fn bitor_assign(&mut self, other: &u8)
sourceimpl<'_, T, O> BitOrAssign<&'_ BitVec<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
impl<'_, T, O> BitOrAssign<&'_ BitVec<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
fn bitor_assign(&mut self, rhs: &BitVec<T, O>)
sourceimpl<T, O> BitOrAssign<BitBox<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
impl<T, O> BitOrAssign<BitBox<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
fn bitor_assign(&mut self, rhs: BitBox<T, O>)
sourceimpl<T, O> BitOrAssign<BitVec<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
impl<T, O> BitOrAssign<BitVec<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
fn bitor_assign(&mut self, rhs: BitVec<T, O>)
sourceimpl<T, O, Rhs> BitOrAssign<Rhs> for BitVec<T, O> where
T: BitStore,
O: BitOrder,
BitSlice<T, O>: BitOrAssign<Rhs>,
impl<T, O, Rhs> BitOrAssign<Rhs> for BitVec<T, O> where
T: BitStore,
O: BitOrder,
BitSlice<T, O>: BitOrAssign<Rhs>,
fn bitor_assign(&mut self, rhs: Rhs)
sourceimpl<'_, A, O> BitOrAssign<&'_ BitArray<A, O>> for BitSlice<<A as BitView>::Store, O> where
A: BitViewSized,
O: BitOrder,
impl<'_, A, O> BitOrAssign<&'_ BitArray<A, O>> for BitSlice<<A as BitView>::Store, O> where
A: BitViewSized,
O: BitOrder,
fn bitor_assign(&mut self, rhs: &BitArray<A, O>)
sourceimpl<A, O, Rhs> BitOrAssign<Rhs> for BitArray<A, O> where
A: BitViewSized,
O: BitOrder,
BitSlice<<A as BitView>::Store, O>: BitOrAssign<Rhs>,
impl<A, O, Rhs> BitOrAssign<Rhs> for BitArray<A, O> where
A: BitViewSized,
O: BitOrder,
BitSlice<<A as BitView>::Store, O>: BitOrAssign<Rhs>,
fn bitor_assign(&mut self, rhs: Rhs)
sourceimpl<'_, T1, T2, O1, O2> BitOrAssign<&'_ BitSlice<T2, O2>> for BitSlice<T1, O1> where
T1: BitStore,
T2: BitStore,
O1: BitOrder,
O2: BitOrder,
impl<'_, T1, T2, O1, O2> BitOrAssign<&'_ BitSlice<T2, O2>> for BitSlice<T1, O1> where
T1: BitStore,
T2: BitStore,
O1: BitOrder,
O2: BitOrder,
sourcefn bitor_assign(&mut self, rhs: &BitSlice<T2, O2>)
fn bitor_assign(&mut self, rhs: &BitSlice<T2, O2>)
Boolean Arithmetic
This merges another bit-slice into self
with a Boolean arithmetic operation.
If the other bit-slice is shorter than self
, it is zero-extended. For BitAnd
,
this clears all excess bits of self
to 0
; for BitOr
and BitXor
, it
leaves them untouched
Behavior
The Boolean operation proceeds across each bit-slice in iteration order. This is
3O(n)
in the length of the shorter of self
and rhs
. However, it can be
accelerated if rhs
has the same type parameters as self
, and both are using
one of the orderings provided by bitvec
. In this case, the implementation
specializes to use BitField
batch operations to operate on the slices one word
at a time, rather than one bit.
Acceleration is not currently provided for custom bit-orderings that use the same storage type.
Pre-1.0
Behavior
In the 0.
development series, Boolean arithmetic was implemented against all
I: Iterator<Item = bool>
. This allowed code such as bits |= [false, true];
,
but forbad acceleration in the most common use case (combining two bit-slices)
because BitSlice
is not such an iterator.
Usage surveys indicate that it is better for the arithmetic operators to operate
on bit-slices, and to allow the possibility of specialized acceleration, rather
than to allow folding against any iterator of bool
s.
If pre-1.0
code relies on this behavior specifically, and has non-BitSlice
arguments to the Boolean sigils, then they will need to be replaced with the
equivalent loop.
Examples
use bitvec::prelude::*;
let a = bits![mut 0, 0, 1, 1];
let b = bits![ 0, 1, 0, 1];
*a ^= b;
assert_eq!(a, bits![0, 1, 1, 0]);
let c = bits![mut 0, 0, 1, 1];
let d = [false, true, false, true];
// no longer allowed
// c &= d.into_iter().by_vals();
for (mut c, d) in c.iter_mut().zip(d.into_iter())
{
*c ^= d;
}
assert_eq!(c, bits![0, 1, 1, 0]);