Crates.io | simple-bits |
lib.rs | simple-bits |
version | 1.0.1 |
source | src |
created_at | 2022-05-15 21:49:16.657332 |
updated_at | 2022-05-15 21:51:11.578326 |
description | A simple Rust trait to extract and replace bits in integer types. |
homepage | https://codentium.com |
repository | https://github.com/StephanvanSchaik/simple-bits |
max_upload_size | |
id | 587350 |
size | 5,531 |
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);