Trait sp_std::ops::BitXor

1.0.0 · source ·
pub trait BitXor<Rhs = Self> {
    type Output;

    fn bitxor(self, rhs: Rhs) -> Self::Output;
}
Expand description

The bitwise XOR operator ^.

Note that Rhs is Self by default, but this is not mandatory.

Examples

An implementation of BitXor that lifts ^ to a wrapper around bool.

use std::ops::BitXor;

#[derive(Debug, PartialEq)]
struct Scalar(bool);

impl BitXor for Scalar {
    type Output = Self;

    // rhs is the "right-hand side" of the expression `a ^ b`
    fn bitxor(self, rhs: Self) -> Self::Output {
        Self(self.0 ^ rhs.0)
    }
}

assert_eq!(Scalar(true) ^ Scalar(true), Scalar(false));
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 BitXor trait for a wrapper around Vec<bool>.

use std::ops::BitXor;

#[derive(Debug, PartialEq)]
struct BooleanVector(Vec<bool>);

impl BitXor for BooleanVector {
    type Output = Self;

    fn bitxor(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![false, true, true, false]);
assert_eq!(bv1 ^ bv2, expected);

Required Associated Types§

The resulting type after applying the ^ operator.

Required Methods§

Performs the ^ operation.

Examples
assert_eq!(true ^ false, true);
assert_eq!(true ^ true, false);
assert_eq!(5u8 ^ 1u8, 4);
assert_eq!(5u8 ^ 2u8, 7);

Implementors§

impl<T, S> BitXor<&AHashSet<T, S>> for &AHashSet<T, S>where
    T: Eq + Hash + Clone,
    S: BuildHasher + Default,

impl<A, O, Rhs> BitXor<Rhs> for BitArray<A, O>where
    A: BitViewSized,
    O: BitOrder,
    BitSlice<A::Store, O>: BitXorAssign<Rhs>,

impl<T, O, Rhs> BitXor<Rhs> for BitBox<T, O>where
    T: BitStore,
    O: BitOrder,
    BitSlice<T, O>: BitXorAssign<Rhs>,

impl<T, O, Rhs> BitXor<Rhs> for BitVec<T, O>where
    T: BitStore,
    O: BitOrder,
    BitSlice<T, O>: BitXorAssign<Rhs>,

impl BitXor<Limb> for Limb

impl<const LIMBS: usize> BitXor<UInt<LIMBS>> for UInt<LIMBS>

impl<const LIMBS: usize> BitXor<&UInt<LIMBS>> for UInt<LIMBS>

impl<const LIMBS: usize> BitXor<UInt<LIMBS>> for &UInt<LIMBS>

impl<const LIMBS: usize> BitXor<&UInt<LIMBS>> for &UInt<LIMBS>

impl<const LIMBS: usize> BitXor<Wrapping<UInt<LIMBS>>> for Wrapping<UInt<LIMBS>>

impl<const LIMBS: usize> BitXor<&Wrapping<UInt<LIMBS>>> for Wrapping<UInt<LIMBS>>

impl<const LIMBS: usize> BitXor<Wrapping<UInt<LIMBS>>> for &Wrapping<UInt<LIMBS>>

impl<const LIMBS: usize> BitXor<&Wrapping<UInt<LIMBS>>> for &Wrapping<UInt<LIMBS>>

impl<T, B> BitXor<B> for BitFlags<T>where
    T: BitFlag,
    B: Into<BitFlags<T>>,

impl<Frac> BitXor<FixedU8<Frac>> for FixedU8<Frac>

impl<Frac> BitXor<FixedU8<Frac>> for &FixedU8<Frac>

impl<Frac> BitXor<&FixedU8<Frac>> for FixedU8<Frac>

impl<Frac> BitXor<&FixedU8<Frac>> for &FixedU8<Frac>

impl<Frac> BitXor<FixedU16<Frac>> for FixedU16<Frac>

impl<Frac> BitXor<FixedU16<Frac>> for &FixedU16<Frac>

impl<Frac> BitXor<&FixedU16<Frac>> for FixedU16<Frac>

impl<Frac> BitXor<&FixedU16<Frac>> for &FixedU16<Frac>

impl<Frac> BitXor<FixedU32<Frac>> for FixedU32<Frac>

impl<Frac> BitXor<FixedU32<Frac>> for &FixedU32<Frac>

impl<Frac> BitXor<&FixedU32<Frac>> for FixedU32<Frac>

impl<Frac> BitXor<&FixedU32<Frac>> for &FixedU32<Frac>

impl<Frac> BitXor<FixedU64<Frac>> for FixedU64<Frac>

impl<Frac> BitXor<FixedU64<Frac>> for &FixedU64<Frac>

impl<Frac> BitXor<&FixedU64<Frac>> for FixedU64<Frac>

impl<Frac> BitXor<&FixedU64<Frac>> for &FixedU64<Frac>

impl<Frac> BitXor<FixedU128<Frac>> for FixedU128<Frac>

impl<Frac> BitXor<FixedU128<Frac>> for &FixedU128<Frac>

impl<Frac> BitXor<&FixedU128<Frac>> for FixedU128<Frac>

impl<Frac> BitXor<&FixedU128<Frac>> for &FixedU128<Frac>

impl<Frac> BitXor<FixedI8<Frac>> for FixedI8<Frac>

impl<Frac> BitXor<FixedI8<Frac>> for &FixedI8<Frac>

impl<Frac> BitXor<&FixedI8<Frac>> for FixedI8<Frac>

impl<Frac> BitXor<&FixedI8<Frac>> for &FixedI8<Frac>

impl<Frac> BitXor<FixedI16<Frac>> for FixedI16<Frac>

impl<Frac> BitXor<FixedI16<Frac>> for &FixedI16<Frac>

impl<Frac> BitXor<&FixedI16<Frac>> for FixedI16<Frac>

impl<Frac> BitXor<&FixedI16<Frac>> for &FixedI16<Frac>

impl<Frac> BitXor<FixedI32<Frac>> for FixedI32<Frac>

impl<Frac> BitXor<FixedI32<Frac>> for &FixedI32<Frac>

impl<Frac> BitXor<&FixedI32<Frac>> for FixedI32<Frac>

impl<Frac> BitXor<&FixedI32<Frac>> for &FixedI32<Frac>

impl<Frac> BitXor<FixedI64<Frac>> for FixedI64<Frac>

impl<Frac> BitXor<FixedI64<Frac>> for &FixedI64<Frac>

impl<Frac> BitXor<&FixedI64<Frac>> for FixedI64<Frac>

impl<Frac> BitXor<&FixedI64<Frac>> for &FixedI64<Frac>

impl<Frac> BitXor<FixedI128<Frac>> for FixedI128<Frac>

impl<Frac> BitXor<FixedI128<Frac>> for &FixedI128<Frac>

impl<Frac> BitXor<&FixedI128<Frac>> for FixedI128<Frac>

impl<Frac> BitXor<&FixedI128<Frac>> for &FixedI128<Frac>

impl<F> BitXor<Unwrapped<F>> for Unwrapped<F>where
    F: BitXor<F, Output = F>,

impl<F> BitXor<Unwrapped<F>> for &Unwrapped<F>where
    for<'a> &'a F: BitXor<F, Output = F>,

impl<F> BitXor<&Unwrapped<F>> for Unwrapped<F>where
    for<'a> F: BitXor<&'a F, Output = F>,

impl<F> BitXor<&Unwrapped<F>> for &Unwrapped<F>where
    for<'a, 'b> &'a F: BitXor<&'b F, Output = F>,

impl<F> BitXor<Wrapping<F>> for Wrapping<F>where
    F: BitXor<F, Output = F>,

impl<F> BitXor<Wrapping<F>> for &Wrapping<F>where
    for<'a> &'a F: BitXor<F, Output = F>,

impl<F> BitXor<&Wrapping<F>> for Wrapping<F>where
    for<'a> F: BitXor<&'a F, Output = F>,

impl<F> BitXor<&Wrapping<F>> for &Wrapping<F>where
    for<'a, 'b> &'a F: BitXor<&'b F, Output = F>,

impl<'a> BitXor<&'a FixedBitSet> for &'a FixedBitSet

impl<T, S> BitXor<&HashSet<T, S, Global>> for &HashSet<T, S>where
    T: Eq + Hash + Clone,
    S: BuildHasher + Default,

impl<T, S1, S2> BitXor<&IndexSet<T, S2>> for &IndexSet<T, S1>where
    T: Eq + Hash + Clone,
    S1: BuildHasher + Default,
    S2: BuildHasher,

impl BitXor<&BigInt> for &BigInt

impl<'a> BitXor<BigInt> for &'a BigInt

impl BitXor<&BigInt> for BigInt

impl BitXor<BigInt> for BigInt

impl BitXor<&Number> for &Number

impl<'a> BitXor<Number> for &'a Number

impl BitXor<&Number> for Number

impl BitXor<Number> for Number

impl<'a, 'b, T, S> BitXor<&'b LinkedHashSet<T, S>> for &'a LinkedHashSet<T, S>where
    T: Eq + Hash + Clone,
    S: BuildHasher + Default,

impl BitXor<OFlag> for OFlag

impl BitXor<FdFlag> for FdFlag

impl BitXor<SFlag> for SFlag

impl BitXor<Mode> for Mode

impl BitXor<BigInt> for BigInt

impl<'a> BitXor<BigInt> for &'a BigInt

impl<'a, 'b> BitXor<&'b BigInt> for &'a BigInt

impl<'a> BitXor<&'a BigInt> for BigInt

impl<'a> BitXor<BigUint> for &'a BigUint

impl<'a, 'b> BitXor<&'b BigUint> for &'a BigUint

impl<'a> BitXor<&'a BigUint> for BigUint

impl BitXor<U128> for U128

impl BitXor<U256> for U256

impl BitXor<U512> for U512

impl<'l, 'r> BitXor<&'r H128> for &'l H128

impl BitXor<H128> for H128

impl<'l, 'r> BitXor<&'r H160> for &'l H160

impl BitXor<H160> for H160

impl<'l, 'r> BitXor<&'r H256> for &'l H256

impl BitXor<H256> for H256

impl<'l, 'r> BitXor<&'r H384> for &'l H384

impl BitXor<H384> for H384

impl<'l, 'r> BitXor<&'r H512> for &'l H512

impl BitXor<H512> for H512

impl<'l, 'r> BitXor<&'r H768> for &'l H768

impl BitXor<H768> for H768

impl BitXor<Access> for Access

impl BitXor<Mode> for Mode

impl BitXor<OFlags> for OFlags

impl BitXor<Parity> for Parity

impl BitXor<AutoSimd<[bool; 1]>> for AutoSimd<[bool; 1]>

impl BitXor<AutoSimd<[bool; 2]>> for AutoSimd<[bool; 2]>

impl BitXor<AutoSimd<[bool; 4]>> for AutoSimd<[bool; 4]>

impl BitXor<AutoSimd<[bool; 8]>> for AutoSimd<[bool; 8]>

impl BitXor<AutoSimd<[bool; 16]>> for AutoSimd<[bool; 16]>

impl BitXor<AutoSimd<[bool; 32]>> for AutoSimd<[bool; 32]>

impl BitXor<Choice> for Choice

impl BitXor<B0> for B0

impl BitXor<B0> for B1

impl BitXor<B1> for B0

impl BitXor<B1> for B1

impl<Ur: Unsigned> BitXor<Ur> for UTerm

impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> BitXor<Ur> for UInt<Ul, Bl>where
    UInt<Ul, Bl>: PrivateXor<Ur>,
    PrivateXorOut<UInt<Ul, Bl>, Ur>: Trim,

impl BitXor<&JsValue> for &JsValue

impl<'a> BitXor<JsValue> for &'a JsValue