1 unstable release

0.1.0 Jul 17, 2020

#21 in #separator

Download history 131/week @ 2024-02-03 224/week @ 2024-02-10 289/week @ 2024-02-17 445/week @ 2024-02-24 375/week @ 2024-03-02 483/week @ 2024-03-09 374/week @ 2024-03-16 220/week @ 2024-03-23 266/week @ 2024-03-30 244/week @ 2024-04-06 238/week @ 2024-04-13 168/week @ 2024-04-20 209/week @ 2024-04-27 271/week @ 2024-05-04 201/week @ 2024-05-11 121/week @ 2024-05-18

829 downloads per month
Used in 3 crates (via h264-profile-level-id)

MIT/Apache

10KB
126 lines

bitpattern

bitwise pattern matching and extracting

Actions Status Crates.io Docs.rs

Usage

[dependencies]
bitpattern = "0.1.0"

Example

    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)));

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~94KB