Trait sp_std::ops::BitOr

1.0.0 · source · []
pub trait BitOr<Rhs = Self> {
    type Output;
    fn bitor(self, rhs: Rhs) -> Self::Output;
}
Expand description

The bitwise OR operator |.

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

Examples

An implementation of BitOr for a wrapper around bool.

use std::ops::BitOr;

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

impl BitOr for Scalar {
    type Output = Self;

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

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

use std::ops::BitOr;

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

impl BitOr for BooleanVector {
    type Output = Self;

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

Associated Types

The resulting type after applying the | operator.

Required methods

Performs the | operation.

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

Implementations on Foreign Types

Returns the union of self and rhs as a new HashSet<T, S>.

Examples
use std::collections::HashSet;

let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([3, 4, 5]);

let set = &a | &b;

let mut i = 0;
let expected = [1, 2, 3, 4, 5];
for x in &set {
    assert!(expected.contains(x));
    i += 1;
}
assert_eq!(i, expected.len());

Implementors

impl<O, V, Rhs> BitOr<Rhs> for BitArray<O, V> where
    O: BitOrder,
    V: BitView,
    BitSlice<O, V::Store>: BitOrAssign<Rhs>, 

impl<R> BitOr<R> for BitMask<R> where
    R: BitRegister

impl<O, T, Rhs> BitOr<Rhs> for BitBox<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T>: BitOrAssign<Rhs>, 

impl<O, T, Rhs> BitOr<Rhs> for BitVec<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T>: BitOrAssign<Rhs>, 

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

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

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

impl<T: Into<Ready>> BitOr<T> for Ready

impl BitOr<BigInt> for BigInt

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

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

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

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

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

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

impl<R: RuleType> BitOr<Operator<R>> for Operator<R>

impl BitOr<U128> for U128

impl BitOr<U256> for U256

impl BitOr<U512> for U512

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

impl BitOr<H128> for H128

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

impl BitOr<H160> for H160

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

impl BitOr<H256> for H256

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

impl BitOr<H512> for H512

impl BitOr<Choice> for Choice

impl BitOr<B0> for B0

impl BitOr<B1> for B0

impl<Rhs: Bit> BitOr<Rhs> for B1

impl<U: Unsigned> BitOr<U> for UTerm

impl<B: Bit, U: Unsigned> BitOr<UTerm> for UInt<U, B>

impl<Ul: Unsigned, Ur: Unsigned> BitOr<UInt<Ur, B0>> for UInt<Ul, B0> where
    Ul: BitOr<Ur>, 

impl<Ul: Unsigned, Ur: Unsigned> BitOr<UInt<Ur, B1>> for UInt<Ul, B0> where
    Ul: BitOr<Ur>, 

impl<Ul: Unsigned, Ur: Unsigned> BitOr<UInt<Ur, B0>> for UInt<Ul, B1> where
    Ul: BitOr<Ur>, 

impl<Ul: Unsigned, Ur: Unsigned> BitOr<UInt<Ur, B1>> for UInt<Ul, B1> where
    Ul: BitOr<Ur>,