macro_rules! bitvec {
    ($order:ty, Cell<$store:ident>; $val:expr; $rep:expr) => { ... };
    ($order:ty, $store:ident; $val:expr; $rep:expr) => { ... };
    ($order:ty; $val:expr; $rep:expr) => { ... };
    ($val:expr; $rep:expr) => { ... };
    ($($arg:tt)*) => { ... };
}
Expand description

Constructs a new BitVec from a bit-pattern description.

This macro takes a superset of the vec! argument syntax: it may be invoked with either a sequence of bit expressions, or a single bit expression and a repetition counter. Additionally, you may provide the names of a BitOrder and a BitStore implementor as the BitVec’s type arguments.

Argument Rules

Bit expressions must be integer literals. Ambiguity restrictions in the macro syntax forbid the use of identifiers to existing variables, even const values. These are converted to bool through the expression $val != 0. Any non-zero enteger becomes true, and 0 becomes false.

You may use any name or path to a BitOrder implementation. However, the identifier tokens Lsb0, Msb0, and LocalBits are matched directly and specialized to have compile-time constructions, whereäs any other name or path will not be known to the macro, and will execute at runtime.

The BitStore argument must be the name of an unsigned integer fundamental, an atomic, or a Cell<> wrapper of that unsigned integer. These are matched by token, not by type, and no other identifier as accepted. Using any other token will cause the macro to fail.

Examples

use bitvec::prelude::*;
use core::cell::Cell;

radium::if_atomic! { if atomic(32) {
  use core::sync::atomic::AtomicU32;
} }

let a: BitVec = bitvec![0, 1, 0, 1, 2];
assert_eq!(a.count_ones(), 3);

let b: BitVec = bitvec![2; 5];
assert!(b.all());
assert_eq!(b.len(), 5);

let c = bitvec![Lsb0, Cell<u16>; 0, 1, 0, 0, 1];
let d = bitvec![Msb0, AtomicU32; 0, 0, 1, 0, 1];