Struct cbitmap::bitmap::Bitmap

source ·
pub struct Bitmap<const BYTES: usize> { /* private fields */ }
Expand description

A size-fixed bitmap with croase-granularity (byte) and conventional interfaces.

Generics

  • BYTES: a usize, specifying the byte length of the bitmap.

Note: The actual number of flags (bits) will be BYTES * 8.

Fields

  • bits: Option<Box>. The box holds an array of u8 with fixed length BYTES.

It is allowed to have BYTES == 0. In this case, bits = None.

Examples

Create a new bitmap using methods

use cbitmap::bitmap::*;

// new() will create a bitmap, init the flags to 0:
let map = Bitmap::<1>::new();
// Or use Default::default():
let map: Bitmap<1> = Default::default();

// You can init a map with a [u8; BYTES]:
let map: Bitmap<1> = [0b_10_u8; 1].into();
let map = Bitmap::<1>::from([0b_100_u8; 1]);

// You can also init a map with an unsized integer. The exact
// type of the integer can be omitted, but the `BYTES` must be
// specified:
let map: Bitmap<2> = 0b_10000000_00000001.into();

Create a new bitmap using macros (recommend)

use cbitmap::bitmap::*;

// Bitmap<0>
let map = newmap!();

// newmap!(;bits) = Bitmap<{(bits + 7) / 8}>
let map = newmap!(;35);

// newmap!(mask:literal | mask:literal | ...; bits)
let map = newmap!(1u8 | 0b100000u128; 48);

// newmap!(var | var | ...; bits)
let a = 1u64 << 34;
let b = 1u128 << 47;
let map = newmap!(a | b; 48);

// he_lang!(idx | idx | ...; bits)
let map = he_lang!(1 | 2; 8);

Use immutable methods to inspect bits and bitmap infos

use cbitmap::bitmap::*;

let map: Bitmap<1> = newmap!(0b_10000001; 8);
// bit_len() can get the length of the bitmap in bits,
// while byte_len() get it in bytes:
assert_eq!(map.bit_len(), 8);
assert_eq!(map.byte_len(), 1);
// get_bool() and get_01() can get the value of one bit:
assert_eq!(map.get_bool(0), true);
assert_eq!(map.get_01(7), 1);
// test() is a wrapper of get_bool():
assert_eq!(map.test(2), false);
// range_to_string() can format a range of bits:
let map: Bitmap<2> = newmap!(0b_01_10000000; 16);
assert_eq!(&map.range_to_string(4, 10).unwrap(), "01 1000");

Use mutable methods to manipulate bits

use cbitmap::bitmap::*;

let mut map = newmap!(;8);
// set(), reset() and flip() can modify one bit:
assert_eq!(map.test(1), false);
map.set(1);
assert_eq!(map.test(1), true);
map.reset(1);
assert_eq!(map.test(1), false);
map.flip(1);
assert_eq!(map.test(1), true);
// set_all(), reset_all() and flip_all() can modify the
// whole map:
map.set_all();
assert_eq!(&map.range_to_string(0, 8).unwrap(), "11111111");
// It is also possible to call these methods in chain:
map.reset_all().flip(1);
assert_eq!(map.test(1), true);

Use wrappers to reference single bits

use cbitmap::bitmap::*;

let mut map = newmap!(;8);
// at() can give a immutable ref of a bit, with a wrapper:
let bit0 = map.at(0);
let bit1 = map.at(1);

// Panic! Since map has already referenced by bit0 and bit1
// map.set(1);

// Use deref to peek the bit:
assert_eq!(*bit0, false);

{
    let mut bitmut = map.at_mut(1);
    bitmut.set();
}
assert_eq!(*map.at(1), true);

Use bitwise operators

use cbitmap::bitmap::*;

let mut map = newmap!(;8);

map |= 1u8 << 4;
assert_eq!(map.test(4), true);

map |= 0b_11000000u8;

// To use &, map shoule be in ref and be on the left:
assert_eq!(&map & 0b_11010000_u8, 0b11010000);

map &= 1u8 << 7;
assert_eq!(&map & !0u8, 1u8 << 7);

Implementations§

source§

impl<const BYTES: usize> Bitmap<BYTES>

source

pub fn range_to_string(&self, start: usize, end: usize) -> Option<String>

Format a range of bits into a Option<String>.

An array of '0'/'1' will show in the String. The bits are separated by ' ' at the edge of 2 bytes.

Return

None if the range is invalid (out of the bitmap, or length is less than 0), [Some(String)] otherwise.

Examples
use cbitmap::bitmap::*;
 
let map: Bitmap<2> = 0b_011_11001100.into();
let string = map.range_to_string(2, 11).unwrap();
assert_eq!(&string, "011 110011");
 
assert!(map.range_to_string(0, 100).is_none());
assert!(map.range_to_string(100, 101).is_none());
assert!(map.range_to_string(2, 1).is_none());
source§

impl<const BYTES: usize> Bitmap<BYTES>

source

pub fn at<'map>(&'map self, index: usize) -> BitRef<'map, BYTES>

Get the immutable reference of the indexed bit in the bitmap. The bit is wrapped in BitRef.

One can deref this reference to get the bool value of the bit.

Examples

Simple examples:

use cbitmap::bitmap::*;

let map = newmap!(0b_00001000; 8);
let bit = map.at(3);
assert_eq!(*bit, true);
Panics

Panic if index is out of range.

source

pub fn at_mut<'map>(&'map mut self, index: usize) -> BitRefMut<'map, BYTES>

Get the mutable reference of the indexed bit in the bitmap. The bit is wrapped in BitRefMut.

One can deref this reference to get the bool value of the bit, or use the methods to modify the referenced bit.

Examples

Simple examples:

use cbitmap::bitmap::*;

let mut map = newmap!(0b_00001000; 8);
{
    let mut bitmut = map.at_mut(3);
    assert_eq!(*bitmut, true);
    bitmut.reset();
    assert_eq!(*bitmut, false);
}
Panics

Panic if index is out of range.

source§

impl<const BYTES: usize> Bitmap<BYTES>

source

pub fn as_ref(&self) -> &[u8; BYTES]

source

pub fn as_mut(&mut self) -> &mut [u8; BYTES]

source

pub fn as_ptr(&self) -> *const u8

source

pub fn as_mut_ptr(&mut self) -> *mut u8

source§

impl<const BYTES: usize> Bitmap<BYTES>

source

pub fn new() -> Self

Create a Bitmap<BYTES> whose flags are all set to 0.

Examples
use cbitmap::bitmap::Bitmap;

let map = Bitmap::<2>::new();
assert_eq!(&map.range_to_string(0, 16).unwrap(),
           "00000000 00000000");
source

pub const fn bit_len(&self) -> usize

Get the length of the bitmap in bits.

Examples
use cbitmap::bitmap::*;

let map = newmap!(;24);
assert_eq!(map.bit_len(), 24);
source

pub const fn byte_len(&self) -> usize

Get the length of the bitmap in bytes.

Examples
use cbitmap::bitmap::*;

let map = newmap!(;3 * 8);
assert_eq!(map.byte_len(), 3);

Trait Implementations§

source§

impl<const BYTES: usize, const N: usize> BitAnd<[u8; N]> for &Bitmap<BYTES>

source§

fn bitand(self, rhs: [u8; N]) -> Self::Output

AND the given bitmap (in ref) to an array of u8 values.

Generics
  • BYTES: the byte length of the bitmap.
  • N: the length of the u8 array.
Examples

A & can AND the bitmap with a fixed-length u8 array, the results will be store in a new array:

use cbitmap::bitmap::*;

let mut map = Bitmap::<2>::from([255u8; 2]);
let arr = [1u8; 2];
// NOTE: the bitmap shoule be in ref, and should be in left.
assert_eq!(&map & arr, [1u8; 2]);

There are also aliases for integer types:

use cbitmap::bitmap::*;
 
let mut map = Bitmap::<1>::from(255u8);
let arr = 1u8;
assert_eq!(&map & arr, 1u8);
See

About the asymmetry between BYTES and N, see bitmap::Bitmap<BYTES>::bitand_assign.

In general, if N > BYTES, the returned array will have (N - BYTES) * 8 leading zero flags.

§

type Output = [u8; N]

The resulting type after applying the & operator.
source§

impl<const BYTES: usize> BitAnd<char> for &Bitmap<BYTES>

§

type Output = char

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: char) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<i128> for &Bitmap<BYTES>

§

type Output = i128

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: i128) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<i16> for &Bitmap<BYTES>

§

type Output = i16

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: i16) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<i32> for &Bitmap<BYTES>

§

type Output = i32

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: i32) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<i64> for &Bitmap<BYTES>

§

type Output = i64

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: i64) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<i8> for &Bitmap<BYTES>

§

type Output = i8

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: i8) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<isize> for &Bitmap<BYTES>

§

type Output = isize

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: isize) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<u128> for &Bitmap<BYTES>

§

type Output = u128

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: u128) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<u16> for &Bitmap<BYTES>

§

type Output = u16

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: u16) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<u32> for &Bitmap<BYTES>

§

type Output = u32

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: u32) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<u64> for &Bitmap<BYTES>

§

type Output = u64

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: u64) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<u8> for &Bitmap<BYTES>

§

type Output = u8

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: u8) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize> BitAnd<usize> for &Bitmap<BYTES>

§

type Output = usize

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: usize) -> Self::Output

Performs the & operation. Read more
source§

impl<const BYTES: usize, const N: usize> BitAndAssign<[u8; N]> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: [u8; N])

AND the given bitmap with an array of u8 values.

Generics
  • BYTES: the byte length of the bitmap.
  • N: the length of the u8 array.
Examples

A simple example:

use cbitmap::bitmap::*;

let mut map = Bitmap::<1>::from([0b_11111111_u8; 1]);
map &= [0b_11111110_u8; 1];
assert_eq!(map.test(0), false);

There are also aliases for integer types:

use cbitmap::bitmap::*;
 
let mut map = Bitmap::<1>::from(255u8);
map &= 0b_11111110u8;
assert_eq!(map.test(0), false);

It is also noteworthy that, if the bitmap is longer than the array, then the rest of bitmap will be set to all-zero.

use cbitmap::bitmap::*;

let mut map: Bitmap::<2> = [255u8; 2].into();
map &= 255u8;

assert_eq!(&map.range_to_string(8, 16).unwrap(), "00000000");
source§

impl<const BYTES: usize> BitAndAssign<char> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: char)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<i128> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: i128)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<i16> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: i16)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<i32> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: i32)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<i64> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: i64)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<i8> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: i8)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<isize> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: isize)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<u128> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: u128)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<u16> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: u16)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<u32> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: u32)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<u64> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: u64)

Performs the &= operation. Read more
source§

impl<const BYTES: usize> BitAndAssign<u8> for Bitmap<BYTES>

source§

fn bitand_assign(&mut self, rhs: u8)

Performs the &= operation. Read more
source§

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

source§

fn bitand_assign(&mut self, rhs: usize)

Performs the &= operation. Read more
source§

impl<const BYTES: usize, const N: usize> BitOrAssign<[u8; N]> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: [u8; N])

OR the given bitmap with an array of u8 values.

Generics
  • BYTES: the byte length of the bitmap.
  • N: the length of the u8 array.
Examples

A simple example:

use cbitmap::bitmap::*;

let mut map = Bitmap::<1>::from([0u8; 1]);
map |= [0b_00000001_u8; 1];
assert_eq!(map.test(0), true);

There are also aliases for integer types:

use cbitmap::bitmap::*;

let mut map = Bitmap::<1>::from(0u8);
map |= 0b_00000001_u8;
assert_eq!(map.test(0), true);
source§

impl<const BYTES: usize> BitOrAssign<char> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: char)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<i128> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: i128)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<i16> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: i16)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<i32> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: i32)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<i64> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: i64)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<i8> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: i8)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<isize> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: isize)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<u128> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: u128)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<u16> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: u16)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<u32> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: u32)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<u64> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: u64)

Performs the |= operation. Read more
source§

impl<const BYTES: usize> BitOrAssign<u8> for Bitmap<BYTES>

source§

fn bitor_assign(&mut self, rhs: u8)

Performs the |= operation. Read more
source§

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

source§

fn bitor_assign(&mut self, rhs: usize)

Performs the |= operation. Read more
source§

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

source§

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

Get the value of a bit by sepcifying the index.

Arguments
  • index: the index of the bit.
Examples

A simple example:

use cbitmap::bitmap::*;

let map = newmap!(0b_1; 8);
assert_eq!(map.get_bool(0), true);
Panics

Panic if the index is out of range.

source§

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

Get the minimal index of a ‘1’ in the bitmap.

Return

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

Examples
use cbitmap::bitmap::*;

let mut map = newmap!(;16);
assert_eq!(map.find_first_one(), None);
map.set(10);
assert_eq!(map.find_first_one(), Some(10));
map.set(7);
assert_eq!(map.find_first_one(), Some(7));
map.set(0);
assert_eq!(map.find_first_one(), Some(0));
source§

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

Get the minimal index of a ‘0’ in the bitmap.

Return

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

Examples
use cbitmap::bitmap::*;

let mut map = newmap!(;16);
map.set_all();
assert_eq!(map.find_first_zero(), None);
map.reset(10);
assert_eq!(map.find_first_zero(), Some(10));
map.reset(7);
assert_eq!(map.find_first_zero(), Some(7));
map.reset(0);
assert_eq!(map.find_first_zero(), Some(0));
source§

fn count(&self) -> usize

Count how many ’1’s are in the bitmap.

Examples
use cbitmap::bitmap::*;

let mut map = newmap!(;64);
assert_eq!(map.count(), 0);
let some = [
    0b11, 0b110, 0b101, 0b1010,
    0b1111, 0b1, 0b10000, 0b01];
map.fill_prefix(some);
assert_eq!(map.count(), 15);
map.flip_all();
assert_eq!(map.count(), 49);
map.set_all();
assert_eq!(map.count(), 64);
source§

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

Set a bit to 1 by specifying the index.

Return

&mut self, allowing a call chain.

Examples

Examples including call chain:

use cbitmap::bitmap::*;

let mut map = newmap!(;8);
map.set(0);
assert_eq!(map.test(0), true);

map.set(1).set(2).set(3);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "00001111");
source§

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

Set a bit to 0 by specifying the index.

Return

&mut self, allowing a call chain.

Examples

Examples including call chain:

use cbitmap::bitmap::*;

let mut map = newmap!(0b_11111111; 8);
map.reset(0);
assert_eq!(map.test(0), false);

map.reset(1).reset(2).reset(3);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "11110000");
source§

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

Flip a bit by specifying the index.

Return

&mut self, allowing a call chain.

Examples

Examples including call chain:

use cbitmap::bitmap::*;

let mut map = newmap!(;8);
map.flip(0);
assert_eq!(map.test(0), true);

map.flip(1).flip(0);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "00000010");
source§

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

Set the whole map to 1.

Return

&mut self, allowing a call chain.

Examples

Examples including call chain:

use cbitmap::bitmap::*;

let mut map = newmap!(;8);
map.set_all().flip(1);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "11111101");
source§

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

Set the whole map to 0.

Return

&mut self, allowing a call chain.

Examples

Examples including call chain:

use cbitmap::bitmap::*;

let mut map = newmap!(0b11111111; 8);
map.reset_all().flip(1);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "00000010");
source§

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

Flip the whole map.

Return

&mut self, allowing a call chain.

Examples

Examples including call chain:

use cbitmap::bitmap::*;

let mut map = newmap!(0b_10101010; 8);
map.flip_all();
assert_eq!(&map.range_to_string(0, 8).unwrap(), "01010101");

map.flip_all().set(0);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "10101011");
source§

fn all(&self) -> bool

source§

fn any(&self) -> bool

source§

fn none(&self) -> bool

source§

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

Get the value of a bit by sepcifying the index. A wrapper of get_bool(). Read more
source§

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

Get the value of a bit by sepcifying the index. A wrapper of get_bool(). Read more
source§

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

source§

fn clone(&self) -> Bitmap<BYTES>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Self

Default bitmap. All the bits are set to 0.

source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats a bitmap. Only shows the last 2 bytes if the bitmap is longer. The bytes will be separated by space ' '.

The bits will be arranged from right to left. If the bitmap is longer than 2 bytes, a "..." will show on the left. On the very left, a bracket tells the bit length of the map (in a form like "[N bits]"). A space ' ' will be between the bit contents and this bracket.

Examples
use cbitmap::bitmap::*;
 
let mut map: Bitmap<3> = 0.into();
map.set(0);
map.set(8);
let str = &format!("{map}");
assert_eq!(str, "[24 bits] ...00000001 00000001");
source§

impl<const BYTES: usize, const N: usize> FillPrefix<[u8; N]> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: [u8; N]) -> &mut Self

Fill the first N bytes (N*8 bits) of a bitmap with given byte array.

Return

&mut self, allowing a call chain.

Examples
use cbitmap::bitmap::*;
 
let mut map = newmap!(;16);
map.fill_prefix([0b_1010u8; 1]);
assert_eq!(map.test(1), true);
assert_eq!(map.test(3), true);

Here are some aliases:

use cbitmap::bitmap::*;
 
let mut map = newmap!(;128);
// aliases
map.fill_prefix(1u8 << 7);
assert_eq!(map.test(7), true);
map.fill_prefix(1u16 << 15);
assert_eq!(map.test(15), true);
// ... 
map.fill_prefix(1i128 << 100);
assert_eq!(map.test(100), true);
source§

impl<const BYTES: usize> FillPrefix<char> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: char) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<i128> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: i128) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<i16> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: i16) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<i32> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: i32) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<i64> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: i64) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<i8> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: i8) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<isize> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: isize) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<u128> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: u128) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<u16> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: u16) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<u32> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: u32) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<u64> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: u64) -> &mut Self

source§

impl<const BYTES: usize> FillPrefix<u8> for Bitmap<BYTES>

source§

fn fill_prefix(&mut self, value: u8) -> &mut Self

source§

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

source§

fn fill_prefix(&mut self, value: usize) -> &mut Self

source§

impl<const BYTES: usize, const N: usize> From<[u8; N]> for Bitmap<BYTES>

source§

fn from(value: [u8; N]) -> Self

Convert a array [u8; N] into Bitmap<BYTES>.

The generics N and BYTES has not to be equal. If N < BYTES, the bitmap will have BYTES - N bytes of leading zero.

Examples
use cbitmap::bitmap::*;

let map = Bitmap::<2>::from([0u8; 2]);

There are also aliases for integer types:

use cbitmap::bitmap::*;
 
let map = Bitmap::<1>::from(0u8);
source§

impl<const BYTES: usize> From<char> for Bitmap<BYTES>

source§

fn from(value: char) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<i128> for Bitmap<BYTES>

source§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<i16> for Bitmap<BYTES>

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<i32> for Bitmap<BYTES>

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<i64> for Bitmap<BYTES>

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<i8> for Bitmap<BYTES>

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<isize> for Bitmap<BYTES>

source§

fn from(value: isize) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<u128> for Bitmap<BYTES>

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<u16> for Bitmap<BYTES>

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<u32> for Bitmap<BYTES>

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<u64> for Bitmap<BYTES>

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl<const BYTES: usize> From<u8> for Bitmap<BYTES>

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

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

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

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

source§

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

Immutably index into a bit’s bool value.

Inspired by bitvec.

Examples
use cbitmap::bitmap::*;
 
let map = newmap!(0b_10000001;8);
assert_eq!(map[0], true);
assert_eq!(map[4], false);
assert_eq!(map[7], true);
§

type Output = bool

The returned type after indexing.
source§

impl<const BYTES: usize> Into<[u8; BYTES]> for Bitmap<BYTES>

source§

fn into(self) -> [u8; BYTES]

Give the inner array of bitmap.

See

Bitmap.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.