core::ops::BitXor - Rust
Description: API documentation for the Rust `BitXor` trait in crate `core`.
Keywords: rust, rustlang, rust-lang, BitXor

# Trait core::ops::BitXor 1.0.0 [−] [src]

    pub trait BitXor<RHS = Self> {
        type Output;
        fn bitxor(self, rhs: RHS) -> Self::Output;
    }

The `BitXor` trait is used to specify the functionality of `^`.

# Examples

In this example, the `^` operator is lifted to a trivial `Scalar` type.

    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 {
            Scalar(self.0 ^ rhs.0)
        }
    }

    fn main() {
        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));
    }Run

In this example, the `BitXor` trait is implemented for a `BooleanVector` struct.

    use std::ops::BitXor;

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

    impl BitXor for BooleanVector {
        type Output = Self;

        fn bitxor(self, BooleanVector(rhs): Self) -> Self {
            let BooleanVector(lhs) = self;
            assert_eq!(lhs.len(), rhs.len());
            BooleanVector(lhs.iter()
                             .zip(rhs.iter())
                             .map(|(x, y)| (*x || *y) && !(*x && *y))
                             .collect())
        }
    }

    fn main() {
        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);
    }Run

## Associated Types

### `type Output`

The resulting type after applying the `^` operator

## Required Methods

### `fn bitxor(self, rhs: RHS) -> Self::Output`

The method for the `^` operator

## Implementors

- `impl BitXor for Wrapping<usize>`
- `impl<'a> BitXor<Wrapping<usize>> for &'a Wrapping<usize>`
- `impl<'a> BitXor<&'a Wrapping<usize>> for Wrapping<usize>`
- `impl<'a, 'b> BitXor<&'a Wrapping<usize>> for &'b Wrapping<usize>`
- `impl BitXor for Wrapping<u8>`
- `impl<'a> BitXor<Wrapping<u8>> for &'a Wrapping<u8>`
- `impl<'a> BitXor<&'a Wrapping<u8>> for Wrapping<u8>`
- `impl<'a, 'b> BitXor<&'a Wrapping<u8>> for &'b Wrapping<u8>`
- `impl BitXor for Wrapping<u16>`
- `impl<'a> BitXor<Wrapping<u16>> for &'a Wrapping<u16>`
- `impl<'a> BitXor<&'a Wrapping<u16>> for Wrapping<u16>`
- `impl<'a, 'b> BitXor<&'a Wrapping<u16>> for &'b Wrapping<u16>`
- `impl BitXor for Wrapping<u32>`
- `impl<'a> BitXor<Wrapping<u32>> for &'a Wrapping<u32>`
- `impl<'a> BitXor<&'a Wrapping<u32>> for Wrapping<u32>`
- `impl<'a, 'b> BitXor<&'a Wrapping<u32>> for &'b Wrapping<u32>`
- `impl BitXor for Wrapping<u64>`
- `impl<'a> BitXor<Wrapping<u64>> for &'a Wrapping<u64>`
- `impl<'a> BitXor<&'a Wrapping<u64>> for Wrapping<u64>`
- `impl<'a, 'b> BitXor<&'a Wrapping<u64>> for &'b Wrapping<u64>`
- `impl BitXor for Wrapping<isize>`
- `impl<'a> BitXor<Wrapping<isize>> for &'a Wrapping<isize>`
- `impl<'a> BitXor<&'a Wrapping<isize>> for Wrapping<isize>`
- `impl<'a, 'b> BitXor<&'a Wrapping<isize>> for &'b Wrapping<isize>`
- `impl BitXor for Wrapping<i8>`
- `impl<'a> BitXor<Wrapping<i8>> for &'a Wrapping<i8>`
- `impl<'a> BitXor<&'a Wrapping<i8>> for Wrapping<i8>`
- `impl<'a, 'b> BitXor<&'a Wrapping<i8>> for &'b Wrapping<i8>`
- `impl BitXor for Wrapping<i16>`
- `impl<'a> BitXor<Wrapping<i16>> for &'a Wrapping<i16>`
- `impl<'a> BitXor<&'a Wrapping<i16>> for Wrapping<i16>`
- `impl<'a, 'b> BitXor<&'a Wrapping<i16>> for &'b Wrapping<i16>`
- `impl BitXor for Wrapping<i32>`
- `impl<'a> BitXor<Wrapping<i32>> for &'a Wrapping<i32>`
- `impl<'a> BitXor<&'a Wrapping<i32>> for Wrapping<i32>`
- `impl<'a, 'b> BitXor<&'a Wrapping<i32>> for &'b Wrapping<i32>`
- `impl BitXor for Wrapping<i64>`
- `impl<'a> BitXor<Wrapping<i64>> for &'a Wrapping<i64>`
- `impl<'a> BitXor<&'a Wrapping<i64>> for Wrapping<i64>`
- `impl<'a, 'b> BitXor<&'a Wrapping<i64>> for &'b Wrapping<i64>`
- `impl BitXor for bool`
- `impl<'a> BitXor<bool> for &'a bool`
- `impl<'a> BitXor<&'a bool> for bool`
- `impl<'a, 'b> BitXor<&'a bool> for &'b bool`
- `impl BitXor for usize`
- `impl<'a> BitXor<usize> for &'a usize`
- `impl<'a> BitXor<&'a usize> for usize`
- `impl<'a, 'b> BitXor<&'a usize> for &'b usize`
- `impl BitXor for u8`
- `impl<'a> BitXor<u8> for &'a u8`
- `impl<'a> BitXor<&'a u8> for u8`
- `impl<'a, 'b> BitXor<&'a u8> for &'b u8`
- `impl BitXor for u16`
- `impl<'a> BitXor<u16> for &'a u16`
- `impl<'a> BitXor<&'a u16> for u16`
- `impl<'a, 'b> BitXor<&'a u16> for &'b u16`
- `impl BitXor for u32`
- `impl<'a> BitXor<u32> for &'a u32`
- `impl<'a> BitXor<&'a u32> for u32`
- `impl<'a, 'b> BitXor<&'a u32> for &'b u32`
- `impl BitXor for u64`
- `impl<'a> BitXor<u64> for &'a u64`
- `impl<'a> BitXor<&'a u64> for u64`
- `impl<'a, 'b> BitXor<&'a u64> for &'b u64`
- `impl BitXor for isize`
- `impl<'a> BitXor<isize> for &'a isize`
- `impl<'a> BitXor<&'a isize> for isize`
- `impl<'a, 'b> BitXor<&'a isize> for &'b isize`
- `impl BitXor for i8`
- `impl<'a> BitXor<i8> for &'a i8`
- `impl<'a> BitXor<&'a i8> for i8`
- `impl<'a, 'b> BitXor<&'a i8> for &'b i8`
- `impl BitXor for i16`
- `impl<'a> BitXor<i16> for &'a i16`
- `impl<'a> BitXor<&'a i16> for i16`
- `impl<'a, 'b> BitXor<&'a i16> for &'b i16`
- `impl BitXor for i32`
- `impl<'a> BitXor<i32> for &'a i32`
- `impl<'a> BitXor<&'a i32> for i32`
- `impl<'a, 'b> BitXor<&'a i32> for &'b i32`
- `impl BitXor for i64`
- `impl<'a> BitXor<i64> for &'a i64`
- `impl<'a> BitXor<&'a i64> for i64`
- `impl<'a, 'b> BitXor<&'a i64> for &'b i64`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)