1 个不稳定版本

0.1.0 2020年7月17日

#22#separator

Download history 541/week @ 2024-03-14 264/week @ 2024-03-21 250/week @ 2024-03-28 255/week @ 2024-04-04 270/week @ 2024-04-11 143/week @ 2024-04-18 203/week @ 2024-04-25 194/week @ 2024-05-02 291/week @ 2024-05-09 158/week @ 2024-05-16 119/week @ 2024-05-23 374/week @ 2024-05-30 187/week @ 2024-06-06 180/week @ 2024-06-13 122/week @ 2024-06-20 93/week @ 2024-06-27

617 每月下载量
3 个 crate 中使用(通过 h264-profile-level-id

MIT/Apache

10KB
126

bitpattern

位运算模式匹配和提取

Actions Status Crates.io Docs.rs

用法

[dependencies]
bitpattern = "0.1.0"

示例

    let x = 0xacu8; // 10101100

    // '0' means the bit must be 0.
    // '1' means the bit must be 1.
    // '_' can be uses as separator.
    assert_eq!(bitpattern!("1010_1100", x), Some(()));
    assert_eq!(bitpattern!("1010_0100", x), None);

    // '?' means the bit can be 0 or 1.
    assert_eq!(bitpattern!("1?10_1?00", x), Some(()));

    // Other charactors can be used for extracting.
    // 'a' extracts a single bit.
    assert_eq!(bitpattern!("1a10_1100", x), Some(0));
    assert_eq!(bitpattern!("10a0_1100", x), Some(1));

    // Multi-bit extracting by continuous charactors.
    assert_eq!(bitpattern!("1aaa_a100", x), Some(5));

    // Multiple extracting.
    assert_eq!(bitpattern!("1aa0_aa00", x), Some((1, 3)));

    // If the extracting fields are adjacent, the different charactors can be used.
    assert_eq!(bitpattern!("1aab_bccc", x), Some((1, 1, 4)));

许可证

许可协议为以下之一

任选其一。

贡献

除非您明确表示,否则根据 Apache-2.0 许可证定义的,任何有意提交以包含在作品中的贡献,都将根据上述许可进行双重许可,不附加任何额外的条款或条件。

依赖项

~94KB