#bit #set-bit #field #range #integral #traits #operations

no-std bit_field

Simple bit field trait providing get_bit, get_bits, set_bit, and set_bits methods for Rust's integral types

13 releases (8 breaking)

Uses old Rust 2015

0.10.2 Feb 25, 2023
0.10.1 Aug 23, 2020
0.10.0 May 3, 2019
0.9.0 Nov 15, 2017
0.4.0 Jul 12, 2016

#237 in Rust patterns

Download history 179526/week @ 2024-07-22 190851/week @ 2024-07-29 175546/week @ 2024-08-05 209527/week @ 2024-08-12 190692/week @ 2024-08-19 182278/week @ 2024-08-26 174853/week @ 2024-09-02 173507/week @ 2024-09-09 167366/week @ 2024-09-16 186118/week @ 2024-09-23 193892/week @ 2024-09-30 186525/week @ 2024-10-07 205121/week @ 2024-10-14 197866/week @ 2024-10-21 205874/week @ 2024-10-28 198590/week @ 2024-11-04

821,657 downloads per month
Used in 365 crates (93 directly)

Apache-2.0/MIT

29KB
532 lines

bit_field

A simple crate which provides the BitField trait, which provides methods for operating on individual bits and ranges of bits on Rust's integral types.

Documentation

Documentation is available on docs.rs

Usage

[dependencies]
bit_field = "0.10.1"

Example

extern crate bit_field;
use bit_field::BitField;

let mut x: u8 = 0;

x.set_bit(7, true);
assert_eq!(x, 0b1000_0000);

x.set_bits(0..4, 0b1001);
assert_eq!(x, 0b1000_1001);

License

This crate is dual-licensed under MIT or the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.


lib.rs:

Provides the abstraction of a bit field, which allows for bit-level update and retrieval operations.

No runtime deps