Trait sp_std::ops::BitAnd

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

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

The bitwise AND operator &.

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

Examples

An implementation of BitAnd for a wrapper around bool.

use std::ops::BitAnd;

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

impl BitAnd for Scalar {
    type Output = Self;

    // rhs is the "right-hand side" of the expression `a & b`
    fn bitand(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(false));
assert_eq!(Scalar(false) & Scalar(true), Scalar(false));
assert_eq!(Scalar(false) & Scalar(false), Scalar(false));

An implementation of BitAnd for a wrapper around Vec<bool>.

use std::ops::BitAnd;

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

impl BitAnd for BooleanVector {
    type Output = Self;

    fn bitand(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, false, false, 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, false);
assert_eq!(true & true, true);
assert_eq!(5u8 & 1u8, 1);
assert_eq!(5u8 & 2u8, 0);

Implementors§

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

impl<A, O, Rhs> BitAnd<Rhs> for BitArray<A, O>where
    A: BitViewSized,
    O: BitOrder,
    BitSlice<A::Store, O>: BitAndAssign<Rhs>,

impl<T, O, Rhs> BitAnd<Rhs> for BitBox<T, O>where
    T: BitStore,
    O: BitOrder,
    BitSlice<T, O>: BitAndAssign<Rhs>,

impl<R> BitAnd<R> for BitMask<R>where
    R: BitRegister,

impl<T, O, Rhs> BitAnd<Rhs> for BitVec<T, O>where
    T: BitStore,
    O: BitOrder,
    BitSlice<T, O>: BitAndAssign<Rhs>,

impl BitAnd<Limb> for Limb

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

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

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

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

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

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

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

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

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

impl<Frac> BitAnd<FixedU8<Frac>> for FixedU8<Frac>

impl<Frac> BitAnd<FixedU8<Frac>> for &FixedU8<Frac>

impl<Frac> BitAnd<&FixedU8<Frac>> for FixedU8<Frac>

impl<Frac> BitAnd<&FixedU8<Frac>> for &FixedU8<Frac>

impl<Frac> BitAnd<FixedU16<Frac>> for FixedU16<Frac>

impl<Frac> BitAnd<FixedU16<Frac>> for &FixedU16<Frac>

impl<Frac> BitAnd<&FixedU16<Frac>> for FixedU16<Frac>

impl<Frac> BitAnd<&FixedU16<Frac>> for &FixedU16<Frac>

impl<Frac> BitAnd<FixedU32<Frac>> for FixedU32<Frac>

impl<Frac> BitAnd<FixedU32<Frac>> for &FixedU32<Frac>

impl<Frac> BitAnd<&FixedU32<Frac>> for FixedU32<Frac>

impl<Frac> BitAnd<&FixedU32<Frac>> for &FixedU32<Frac>

impl<Frac> BitAnd<FixedU64<Frac>> for FixedU64<Frac>

impl<Frac> BitAnd<FixedU64<Frac>> for &FixedU64<Frac>

impl<Frac> BitAnd<&FixedU64<Frac>> for FixedU64<Frac>

impl<Frac> BitAnd<&FixedU64<Frac>> for &FixedU64<Frac>

impl<Frac> BitAnd<FixedU128<Frac>> for FixedU128<Frac>

impl<Frac> BitAnd<FixedU128<Frac>> for &FixedU128<Frac>

impl<Frac> BitAnd<&FixedU128<Frac>> for FixedU128<Frac>

impl<Frac> BitAnd<&FixedU128<Frac>> for &FixedU128<Frac>

impl<Frac> BitAnd<FixedI8<Frac>> for FixedI8<Frac>

impl<Frac> BitAnd<FixedI8<Frac>> for &FixedI8<Frac>

impl<Frac> BitAnd<&FixedI8<Frac>> for FixedI8<Frac>

impl<Frac> BitAnd<&FixedI8<Frac>> for &FixedI8<Frac>

impl<Frac> BitAnd<FixedI16<Frac>> for FixedI16<Frac>

impl<Frac> BitAnd<FixedI16<Frac>> for &FixedI16<Frac>

impl<Frac> BitAnd<&FixedI16<Frac>> for FixedI16<Frac>

impl<Frac> BitAnd<&FixedI16<Frac>> for &FixedI16<Frac>

impl<Frac> BitAnd<FixedI32<Frac>> for FixedI32<Frac>

impl<Frac> BitAnd<FixedI32<Frac>> for &FixedI32<Frac>

impl<Frac> BitAnd<&FixedI32<Frac>> for FixedI32<Frac>

impl<Frac> BitAnd<&FixedI32<Frac>> for &FixedI32<Frac>

impl<Frac> BitAnd<FixedI64<Frac>> for FixedI64<Frac>

impl<Frac> BitAnd<FixedI64<Frac>> for &FixedI64<Frac>

impl<Frac> BitAnd<&FixedI64<Frac>> for FixedI64<Frac>

impl<Frac> BitAnd<&FixedI64<Frac>> for &FixedI64<Frac>

impl<Frac> BitAnd<FixedI128<Frac>> for FixedI128<Frac>

impl<Frac> BitAnd<FixedI128<Frac>> for &FixedI128<Frac>

impl<Frac> BitAnd<&FixedI128<Frac>> for FixedI128<Frac>

impl<Frac> BitAnd<&FixedI128<Frac>> for &FixedI128<Frac>

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

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

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

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

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

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

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

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

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

impl<T, S, A> BitAnd<&HashSet<T, S, A>> for &HashSet<T, S, A>where
    T: Eq + Hash + Clone,
    S: BuildHasher + Default,
    A: Allocator + Clone,

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

impl BitAnd<&BigInt> for &BigInt

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

impl BitAnd<&BigInt> for BigInt

impl BitAnd<BigInt> for BigInt

impl BitAnd<&Number> for &Number

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

impl BitAnd<&Number> for Number

impl BitAnd<Number> for Number

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

impl BitAnd<OFlag> for OFlag

impl BitAnd<FdFlag> for FdFlag

impl BitAnd<SFlag> for SFlag

impl BitAnd<Mode> for Mode

impl BitAnd<BigInt> for BigInt

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

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

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

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

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

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

impl BitAnd<U128> for U128

impl BitAnd<U256> for U256

impl BitAnd<U512> for U512

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

impl BitAnd<H128> for H128

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

impl BitAnd<H160> for H160

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

impl BitAnd<H256> for H256

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

impl BitAnd<H384> for H384

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

impl BitAnd<H512> for H512

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

impl BitAnd<H768> for H768

impl BitAnd<Access> for Access

impl BitAnd<Mode> for Mode

impl BitAnd<OFlags> for OFlags

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

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

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

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

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

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

impl BitAnd<Choice> for Choice

impl BitAnd<Ready> for Ready

impl<Rhs: Bit> BitAnd<Rhs> for B0

impl BitAnd<B0> for B1

impl BitAnd<B1> for B1

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

impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> BitAnd<Ur> for UInt<Ul, Bl>where
    UInt<Ul, Bl>: PrivateAnd<Ur>,
    PrivateAndOut<UInt<Ul, Bl>, Ur>: Trim,

impl BitAnd<&JsValue> for &JsValue

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