Trait BitOp

Source
pub trait BitOp:
    Not<Output = Self>
    + BitOrAssign<Self>
    + BitAndAssign<Self>
    + BitXorAssign<Self>
    + BitAnd<Self, Output = Self>
    + Sized {
    // Provided methods
    fn set(&mut self, rhs: Self) { ... }
    fn reset(&mut self, rhs: Self) { ... }
    fn toggle(&mut self, rhs: Self) { ... }
    fn get(self, rhs: Self) -> Self { ... }
}

Provided Methods§

Source

fn set(&mut self, rhs: Self)

Set desired bits

§Examples
use bit_op::{BitOp, bit_u8::*};

let mut x = 0b00001111u8;

x.set(B7);
assert_eq!(x, 0b10001111);

let mut y = 0u8;

y.set(B7 | B0);
assert_eq!(y, 0b10000001);
Source

fn reset(&mut self, rhs: Self)

Reset desired bits

§Examples
use bit_op::{BitOp, bit_u8::*};

let mut x = 0b00001111u8;

x.reset(B0 | B1 | B2 | B3);
assert_eq!(x, 0);

let mut y = 0b11111111u8;

y.reset(B7 | B0);
assert_eq!(y, 0b01111110);
Source

fn toggle(&mut self, rhs: Self)

Toggle desired bits

§Examples
use bit_op::{BitOp, bit_u8::*};

let mut x = 0b00001111u8;

x.toggle(B5 | B4 | B3 | B2);
assert_eq!(x, 0b00110011);

x.toggle(B5 | B4 | B3 | B2);
assert_eq!(x, 0b00001111);
Source

fn get(self, rhs: Self) -> Self

Get desired bits

§Examples
use bit_op::{BitOp, bit_u8::*};

let mut x = 0b10000001u8;

assert_eq!(x.get(B7), 0b10000000);
assert_eq!(x.get(B6), 0b00000000);
assert_eq!(x.get(B0), 0b00000001);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl BitOp for u8

Source§

impl BitOp for u16

Source§

impl BitOp for u32

Source§

impl BitOp for u64

Source§

impl BitOp for u128

Implementors§