Trait scale_info::prelude::ops::BitXorAssign
1.8.0 · source · [−]pub trait BitXorAssign<Rhs = Self> {
fn bitxor_assign(&mut self, rhs: Rhs);
}
Expand description
The bitwise XOR assignment operator ^=
.
Examples
use std::ops::BitXorAssign;
#[derive(Debug, PartialEq)]
struct Personality {
has_soul: bool,
likes_knitting: bool,
}
impl BitXorAssign for Personality {
fn bitxor_assign(&mut self, rhs: Self) {
self.has_soul ^= rhs.has_soul;
self.likes_knitting ^= rhs.likes_knitting;
}
}
let mut personality = Personality { has_soul: false, likes_knitting: true };
personality ^= Personality { has_soul: true, likes_knitting: true };
assert_eq!(personality, Personality { has_soul: true, likes_knitting: false});
Required methods
fn bitxor_assign(&mut self, rhs: Rhs)
fn bitxor_assign(&mut self, rhs: Rhs)
Performs the ^=
operation.
Examples
let mut x = true;
x ^= false;
assert_eq!(x, true);
let mut x = true;
x ^= true;
assert_eq!(x, false);
let mut x: u8 = 5;
x ^= 1;
assert_eq!(x, 4);
let mut x: u8 = 5;
x ^= 2;
assert_eq!(x, 7);
Implementations on Foreign Types
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ i16> for i16
impl<'_> BitXorAssign<&'_ i16> for i16
pub fn bitxor_assign(&mut self, other: &i16)
const: unstable · sourceimpl BitXorAssign<isize> for isize
impl BitXorAssign<isize> for isize
pub fn bitxor_assign(&mut self, other: isize)
const: unstable · sourceimpl BitXorAssign<u128> for u128
impl BitXorAssign<u128> for u128
pub fn bitxor_assign(&mut self, other: u128)
sourceimpl<T, const LANES: usize> BitXorAssign<bool> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> BitXorAssign<bool> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
pub fn bitxor_assign(&mut self, rhs: bool)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ u8> for u8
impl<'_> BitXorAssign<&'_ u8> for u8
pub fn bitxor_assign(&mut self, other: &u8)
const: unstable · sourceimpl BitXorAssign<u32> for u32
impl BitXorAssign<u32> for u32
pub fn bitxor_assign(&mut self, other: u32)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ i32> for i32
impl<'_> BitXorAssign<&'_ i32> for i32
pub fn bitxor_assign(&mut self, other: &i32)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ bool> for bool
impl<'_> BitXorAssign<&'_ bool> for bool
pub fn bitxor_assign(&mut self, other: &bool)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ u16> for u16
impl<'_> BitXorAssign<&'_ u16> for u16
pub fn bitxor_assign(&mut self, other: &u16)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ u128> for u128
impl<'_> BitXorAssign<&'_ u128> for u128
pub fn bitxor_assign(&mut self, other: &u128)
sourceimpl<T, U, const LANES: usize> BitXorAssign<U> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: BitXor<U>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as BitXor<U>>::Output == Simd<T, LANES>,
impl<T, U, const LANES: usize> BitXorAssign<U> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: BitXor<U>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as BitXor<U>>::Output == Simd<T, LANES>,
pub fn bitxor_assign(&mut self, rhs: U)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ i64> for i64
impl<'_> BitXorAssign<&'_ i64> for i64
pub fn bitxor_assign(&mut self, other: &i64)
const: unstable · sourceimpl BitXorAssign<u8> for u8
impl BitXorAssign<u8> for u8
pub fn bitxor_assign(&mut self, other: u8)
const: unstable · sourceimpl BitXorAssign<i64> for i64
impl BitXorAssign<i64> for i64
pub fn bitxor_assign(&mut self, other: i64)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ u32> for u32
impl<'_> BitXorAssign<&'_ u32> for u32
pub fn bitxor_assign(&mut self, other: &u32)
const: unstable · sourceimpl BitXorAssign<i128> for i128
impl BitXorAssign<i128> for i128
pub fn bitxor_assign(&mut self, other: i128)
const: unstable · sourceimpl BitXorAssign<i16> for i16
impl BitXorAssign<i16> for i16
pub fn bitxor_assign(&mut self, other: i16)
const: unstable · sourceimpl BitXorAssign<usize> for usize
impl BitXorAssign<usize> for usize
pub fn bitxor_assign(&mut self, other: usize)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ u64> for u64
impl<'_> BitXorAssign<&'_ u64> for u64
pub fn bitxor_assign(&mut self, other: &u64)
const: unstable · sourceimpl BitXorAssign<u16> for u16
impl BitXorAssign<u16> for u16
pub fn bitxor_assign(&mut self, other: u16)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ i128> for i128
impl<'_> BitXorAssign<&'_ i128> for i128
pub fn bitxor_assign(&mut self, other: &i128)
const: unstable · sourceimpl BitXorAssign<i32> for i32
impl BitXorAssign<i32> for i32
pub fn bitxor_assign(&mut self, other: i32)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ i8> for i8
impl<'_> BitXorAssign<&'_ i8> for i8
pub fn bitxor_assign(&mut self, other: &i8)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ usize> for usize
impl<'_> BitXorAssign<&'_ usize> for usize
pub fn bitxor_assign(&mut self, other: &usize)
const: unstable · sourceimpl BitXorAssign<i8> for i8
impl BitXorAssign<i8> for i8
pub fn bitxor_assign(&mut self, other: i8)
const: unstable · sourceimpl BitXorAssign<u64> for u64
impl BitXorAssign<u64> for u64
pub fn bitxor_assign(&mut self, other: u64)
1.22.0 (const: unstable) · sourceimpl<'_> BitXorAssign<&'_ isize> for isize
impl<'_> BitXorAssign<&'_ isize> for isize
pub fn bitxor_assign(&mut self, other: &isize)
const: unstable · sourceimpl BitXorAssign<bool> for bool
impl BitXorAssign<bool> for bool
pub fn bitxor_assign(&mut self, other: bool)
sourceimpl<T, const LANES: usize> BitXorAssign<Mask<T, LANES>> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> BitXorAssign<Mask<T, LANES>> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
pub fn bitxor_assign(&mut self, rhs: Mask<T, LANES>)
sourceimpl<T, O, Rhs> BitXorAssign<Rhs> for BitBox<T, O> where
T: BitStore,
O: BitOrder,
BitSlice<T, O>: BitXorAssign<Rhs>,
impl<T, O, Rhs> BitXorAssign<Rhs> for BitBox<T, O> where
T: BitStore,
O: BitOrder,
BitSlice<T, O>: BitXorAssign<Rhs>,
pub fn bitxor_assign(&mut self, rhs: Rhs)
sourceimpl<'_, T, O> BitXorAssign<&'_ BitBox<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
impl<'_, T, O> BitXorAssign<&'_ BitBox<T, O>> for BitSlice<T, O> where
T: BitStore,
O: BitOrder,
pub fn bitxor_assign(&mut self, rhs: &BitBox<T, O>)
sourceimpl<'_, T1, T2, O1, O2> BitXorAssign<&'_ BitSlice<T2, O2>> for BitSlice<T1, O1> where
T1: BitStore,
T2: BitStore,
O1: BitOrder,
O2: BitOrder,
impl<'_, T1, T2, O1, O2> BitXorAssign<&'_ BitSlice<T2, O2>> for BitSlice<T1, O1> where
T1: BitStore,
T2: BitStore,
O1: BitOrder,
O2: BitOrder,
sourcepub fn bitxor_assign(&mut self, rhs: &BitSlice<T2, O2>)
pub fn bitxor_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]);