pub trait BitsManage {
Show 15 methods // Required methods fn count(&self) -> usize; fn find_first_one(&self) -> Option<usize>; fn find_first_zero(&self) -> Option<usize>; fn get_bool(&self, index: usize) -> bool; fn set(&mut self, index: usize) -> &mut Self; fn reset(&mut self, index: usize) -> &mut Self; fn flip(&mut self, index: usize) -> &mut Self; fn set_all(&mut self) -> &mut Self; fn reset_all(&mut self) -> &mut Self; fn flip_all(&mut self) -> &mut Self; // Provided methods fn all(&self) -> bool { ... } fn any(&self) -> bool { ... } fn none(&self) -> bool { ... } fn get_01(&self, index: usize) -> u8 { ... } fn test(&self, index: usize) -> bool { ... }
}
Expand description

A general trait, structs which implemented this trait provide interfaces to access a range of bits.

Required Methods§

source

fn count(&self) -> usize

source

fn find_first_one(&self) -> Option<usize>

Find the first ‘1’, returns its index.

Returns

None if there is no ‘1’, [Some(usize)] otherwise.

source

fn find_first_zero(&self) -> Option<usize>

Find the first ‘0’, returns its index.

Returns

None if there is no ‘0’, [Some(usize)] otherwise.

source

fn get_bool(&self, index: usize) -> bool

Get the bool value of indexed bit.

Panics

Panic if index is out of range.

source

fn set(&mut self, index: usize) -> &mut Self

Set the indexed bit to ‘1’.

Panics

Panic if index is out of range.

source

fn reset(&mut self, index: usize) -> &mut Self

Set the indexed bit to ‘0’.

Panics

Panic if index is out of range.

source

fn flip(&mut self, index: usize) -> &mut Self

Flip the indexed bit.

Panics

Panic if index is out of range.

source

fn set_all(&mut self) -> &mut Self

Set all bits to ‘1’.

source

fn reset_all(&mut self) -> &mut Self

Set all bits to ‘0’.

source

fn flip_all(&mut self) -> &mut Self

Flip all bits.

Provided Methods§

source

fn all(&self) -> bool

A wrapper of Bitmap::find_first_zero().

Return

bool. true iff there is no ‘0’ in the bitmap.

Examples
use cbitmap::bitmap::*;

let mut map = newmap!(0b10;16);
assert_eq!(map.all(), false);
map.set_all();
assert_eq!(map.all(), true);
source

fn any(&self) -> bool

A wrapper of Bitmap::find_first_one().

Return

bool. true iff there is ‘1’ in the bitmap.

Examples
use cbitmap::bitmap::*;

let mut map = newmap!(;16);
assert_eq!(map.any(), false);
map.set(10);
assert_eq!(map.any(), true);
source

fn none(&self) -> bool

A wrapper of Bitmap::find_first_one().

Return

bool. true iff there is no ‘1’ in the bitmap.

Examples
use cbitmap::bitmap::*;

let mut map = newmap!(;16);
assert_eq!(map.none(), true);
map.set(10);
assert_eq!(map.none(), false);
source

fn get_01(&self, index: usize) -> u8

Get the value of a bit by sepcifying the index. A wrapper of get_bool().

Arguments
  • index: the index of the bit.
Return

0/1, the exact value of the bit.

Panics

Panic if the index is out of range.

source

fn test(&self, index: usize) -> bool

Get the value of a bit by sepcifying the index. A wrapper of get_bool().

Arguments
  • index: the index of the bit.
Return

bool, the value of the bit.

Panics

Panic if the index is out of range.

Implementors§

source§

impl<const BYTES: usize> BitsManage for Bitmap<BYTES>