File: README.md

package info (click to toggle)
rust-bit 0.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104 kB
  • sloc: makefile: 4
file content (52 lines) | stat: -rw-r--r-- 982 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Bit
[![crates.io version badge](https://img.shields.io/crates/v/bit.svg)](https://crates.io/crates/bit)

`bit` is a library which provides some useful helpers for dealing with bits and
bit ranges. For now it's just a rewrite of
[`rust-bit-field` crate](https://github.com/phil-opp/rust-bit-field), but more
features are planned. Some of them _could_ be:

- Support for arrays and slices.
- `bitflags`-like functionality.

# Usage
Add to your `Cargo.toml`:

```toml
[dependencies]
bit = "0.1"
```

And add to your code:

```rust
extern crate bit;
use bit::BitIndex;
```

# Example
```rust
extern crate bit;
use bit::BitIndex;

fn main() {
    let mut value = 0b11010110u8;

    // 8
    println!("{}", u8::bit_length());

    // true
    println!("{}", value.bit(1));

    // 0b10
    println!("{:#b}", value.bit_range(0..2));

    value
        .set_bit(3, true)
        .set_bit(2, false)
        .set_bit_range(5..8, 0b001);

    // 0b111010
    println!("{:#b}", value);
}
```