[][src]Trait lazy_bytes_cast::Bits

pub trait Bits: Copy + Sized + Not<Output = Self> + BitXor<Output = Self> + BitOr<Output = Self> + BitAnd<Output = Self> + Shl<Output = Self> + From<u8> + Eq {
    fn bit(&self, idx: u8) -> bool { ... }
fn toggle_bit(&mut self, idx: u8) { ... }
fn reset_bits(&mut self) { ... }
fn set_bit(&mut self, idx: u8, value: bool) { ... } }

Bits manipulation interface.

All operations panic on overflow.

use lazy_bytes_cast::Bits;

let mut lolka = 0u128;

assert!(!lolka.bit(1));
lolka.set_bit(1, true);
assert!(lolka.bit(1));

assert!(!lolka.bit(0));
lolka.set_bit(0, true);
assert!(lolka.bit(0));

assert!(!lolka.bit(127));
lolka.toggle_bit(127);
assert!(lolka.bit(127));
lolka.toggle_bit(127);
assert!(!lolka.bit(127));

assert_ne!(lolka, 0);
lolka.reset_bits();
assert_eq!(lolka, 0);

All operations panic on overflow via math ops overflow.

This example panics
use lazy_bytes_cast::Bits;

let mut lolka = 0u8;

lolka.set_bit(9, true);

Provided methods

fn bit(&self, idx: u8) -> bool

Gets bit by index

fn toggle_bit(&mut self, idx: u8)

Gets bit by index

fn reset_bits(&mut self)

Sets all bits to false

fn set_bit(&mut self, idx: u8, value: bool)

Sets bit by index

Loading content...

Implementors

impl Bits for i64[src]

impl Bits for u8[src]

impl Bits for u16[src]

impl Bits for u32[src]

impl Bits for u64[src]

impl Bits for u128[src]

impl Bits for usize[src]

Loading content...