Crates.io | bit_seq |
lib.rs | bit_seq |
version | 0.2.1 |
source | src |
created_at | 2023-06-03 10:38:14.764402 |
updated_at | 2023-06-12 14:37:32.167071 |
description | A procedural macro for creating bit sequences. |
homepage | |
repository | https://github.com/Jozott00/bit_seq |
max_upload_size | |
id | 881528 |
size | 29,301 |
bit_seq is a convenient Rust crate that provides a procedural macro for creating bit sequences. This crate simplifies the generation of bit sequences, increasing readability and reducing the potential for errors. Bit sequences can be specified directly, via hex values, or through identifiers or integers with a specific length. It is particularly useful in systems programming and lower-level hardware or protocol interfacing where bit manipulation is common.
First, add the following in you project cmd-line:
cargo add bit_seq
Then import the crate in your Rust file:
use bit_seq::bseq;
Here are some examples of how to use the bseq
macro:
// Direct raw bit sequence
let t = bseq!(0110 01 0 1);
assert_eq!(t, 0b0110_01_0_1);
// Using hex values
let t = bseq!(01 0x1f);
assert_eq!(t, 0b01_0001_1111);
// Using value length expression
let t = bseq!(3:1 0 0xf:2);
assert_eq!(t, 0b1_0_11);
// Using variable length expression
let var = 0xf;
let t = bseq!(10 var:2);
assert_eq!(t, 0b10_11);
// Using mixed variable types
let var_64: u64 = 0xf;
let var_16: u16 = 0xf;
let t = bseq_8!(var_16:4 var_64:4);
assert_eq!(t, 0xff);
// Using unary operators
assert_eq!(bseq!(!0:6), 0b111111);
You can view the full API documentation here.
Contributions to bit_seq are welcome! Please submit a pull request or create an issue on the GitHub page.
This project is licensed under the MIT license.