simple-bits

Crates.iosimple-bits
lib.rssimple-bits
version1.0.1
sourcesrc
created_at2022-05-15 21:49:16.657332
updated_at2022-05-15 21:51:11.578326
descriptionA simple Rust trait to extract and replace bits in integer types.
homepagehttps://codentium.com
repositoryhttps://github.com/StephanvanSchaik/simple-bits
max_upload_size
id587350
size5,531
S.J.R. van Schaik (StephanvanSchaik)

documentation

README

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);
Commit count: 4

cargo fmt