Skip to content

nobodie/nbitmask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nbitmask


CI Checks

This crate provides an easy to use api to create n sized bitmasks. Bitwise operators are available and you can define the underlying container adapted to your environment.

Supported container types :

  • u8
  • u16
  • u32
  • u64
  • u128

This crate provides support for Serialization via Serde through the optional "serde" feature. Make sure to add it into your Cargo.toml if you want it !

[dependencies]
nbitmask = "1.0.0"

Api sample

use nbitmask::BitMask;

let ones: BitMask<u64> = BitMask::ones(7);
let mut mask: BitMask<u64> = BitMask::zeros(4);

mask.set(0, true).unwrap();
// Will display an out of bound error as bit 4 doesn't exist in mask
mask.set(4, true).unwrap_or_else(|err| println!("{}", err));

mask &= &ones;
println!("mask size didn't change : {}", mask.size());

let mask_copy = mask.clone();

mask <<= 1;
assert_eq!(mask.to_string(), "0100".to_string());

mask >>= 1;
assert_eq!(mask.to_string(), mask_copy.to_string());
assert_eq!(mask, mask_copy);

License

Licensed under either of

at your option.


Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages