simple-bits 1.0.1

A simple Rust trait to extract and replace bits in integer types.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 6 items with examples
  • Size
  • Source code size: 5.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 822.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • StephanvanSchaik/simple-bits
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • StephanvanSchaik

simple-bits

Crates.io Docs

The simple-bits crate provides a simple Rust trait to extract and replace bits in integer types rather than having to rely on bit shifting and masking to manipulate bits. This crate supports no_std environments and has no dependencies.

Simply add the following to your Cargo.toml file to use this crate:

simple-bits = "1"

You can then use this crate as follows:

use simple_bits::BitsExt;

assert_eq!(0xdeadbeef_u32.extract_bits(0..16), 0xbeef);
assert_eq!(0xdeadbeef_u32.extract_bits(16..32), 0xdead);
assert_eq!(0xdeadbeef_u32.replace_bits(0..16, 0xcafe), 0xdeadcafe);