macro_rules! bits {
    (mut $order:ident, Cell<$store:ident>; $($val:expr),* $(,)?) => { ... };
    (mut $order:ident, $store:ident; $($val:expr),* $(,)?) => { ... };
    (mut $order:path, Cell<$store:ident>; $($val:expr),* $(,)?) => { ... };
    (mut $order:path, $store:ident; $($val:expr),* $(,)?) => { ... };
    (mut $order:ident; $($val:expr),* $(,)?) => { ... };
    (mut $order:path; $($val:expr),* $(,)?) => { ... };
    (mut $order:ident, Cell<$store:ident>; $val:expr; $len:expr) => { ... };
    (mut $order:ident, $store:ident; $val:expr; $len:expr) => { ... };
    (mut $order:path, Cell<$store:ident>; $val:expr; $len:expr) => { ... };
    (mut $order:path, $store:ident; $val:expr; $len:expr) => { ... };
    (mut $order:ident; $val:expr; $len:expr) => { ... };
    (mut $order:path; $val:expr; $len:expr) => { ... };
    (mut $($val:expr),* $(,)?) => { ... };
    (mut $val:expr; $len:expr) => { ... };
    ($order:ident, Cell<$store:ident>; $($val:expr),* $(,)?) => { ... };
    ($order:ident, $store:ident; $($val:expr),* $(,)?) => { ... };
    ($order:path, Cell<$store:ident>; $($val:expr),* $(,)?) => { ... };
    ($order:path, $store:ident; $($val:expr),* $(,)?) => { ... };
    ($order:ident; $($val:expr),* $(,)?) => { ... };
    ($order:path; $($val:expr),* $(,)?) => { ... };
    ($order:ident, Cell<$store:ident>; $val:expr; $len:expr) => { ... };
    ($order:ident, $store:ident; $val:expr; $len:expr) => { ... };
    ($order:path, Cell<$store:ident>; $val:expr; $len:expr) => { ... };
    ($order:path, $store:ident; $val:expr; $len:expr) => { ... };
    ($order:ident; $val:expr; $len:expr) => { ... };
    ($order:path; $val:expr; $len:expr) => { ... };
    ($($val:expr),* $(,)?) => { ... };
    ($val:expr; $len:expr) => { ... };
}
Expand description

Creates a borrowed BitSlice in the local scope.

This macro constructs a BitArray temporary and then immediately borrows it as a BitSlice. The compiler should extend the lifetime of the underlying BitArray for the duration of the expression’s lifetime.

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 repetiton counter. Additionally, you may provide the names of a BitOrder and a BitStore implementor as the BitArray’s type arguments. You may also use mut as the first argument of the macro in order to produce an &mut BitSlice reference rather than a &BitSlice immutable reference.

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 is accepted. Using any other token will cause the macro to fail.

Examples

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

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

let a: &BitSlice = bits![0, 1, 0, 1, 2];
assert_eq!(a.count_ones(), 3);

let b: &mut BitSlice = bits![mut 2; 5];
assert!(b.all());
assert_eq!(b.len(), 5);

let c = bits![Lsb0, Cell<u16>; 0, 1, 0, 0, 1];
c.set_aliased(0, true);
let d = bits![Msb0, AtomicU32; 0, 0, 1, 0, 1];
d.set_aliased(0, true);