bit_array

Macro bit_array 

Source
macro_rules! bit_array {
    ($($items:expr),* $(,)?) => { ... };
    (@num_bits $(,)?) => { ... };
    (@num_bits, $head:expr $(, $tail:expr)* $(,)?) => { ... };
    (@num_bytes $(, $items:expr)* $(,)?) => { ... };
}
Expand description

Build a fixed-size bit array from a sequence of booleans

assert_eq!(marrow::bit_array![true],  [0b_1]);
assert_eq!(marrow::bit_array![true, true],  [0b_11]);
assert_eq!(marrow::bit_array![true, true, false],  [0b_011]);
assert_eq!(marrow::bit_array![true, true, false, true],  [0b_1011]);

assert_eq!(
    marrow::bit_array![
        // first byte
        true, true, false, false, true, false, true, false,
        // second byte
        true, true, true, false, true,
    ],
    [0b_01010011, 0b_10111],
);

If all items are const expressions, bit_array can be used in const contexts, e.g.,

const fn func() -> bool {
    3 % 2 == 0
}

const { marrow::bit_array![true, false, func()] }

Rules starting with @num_bits and @num_bytes are internal and are not subject to compatibility guarantees.

See also marrow::bits.