7个版本
| 0.1.1 | 2023年5月29日 |
|---|---|
| 0.1.0 | 2023年5月29日 |
| 0.0.5 | 2023年5月3日 |
#5 in #位运算
每月 70 次下载
10KB
226 行
const-twiddle
位操作实用函数
const-twiddle 是一组位操作实用函数,设计上与 twiddle 类似。它也与 const 兼容,并支持 #![no_std]。
使用方法
将 const-twiddle 添加到您的 Cargo.toml 文件
[dependencies]
const-twiddle = "0.1"
在 const 上下文之外的使用
use const_twiddle::Twiddle;
fn test() {
let mut x = 5;
x.set_bit(0, false);
assert_eq!(x, 4);
assert_eq!(x.with_bit(0, true), 5);
assert_eq!(x.bit(0), false);
}
在 const 上下文中的使用
use const_twiddle::ConstU32;
const fn test() {
// Traits are not supported in const yet
let x = ConstU32(5).with_bit(0, false).0; //x = 4
}
许可证
const-twiddle 使用 MIT 协议授权。有关更多详细信息,请参阅 LICENSE 文件。
依赖关系
~4KB