Macro bitvec::bitarr [−][src]
macro_rules! bitarr {
(for $len : literal, in $order : path, $store : ident) => { ... };
(for $len : literal, in $store : ident) => { ... };
(for $len : literal) => { ... };
($order : ident, $store : ident ; $($val : expr), * $(,) ?) => { ... };
($order : path, $store : ident ; $($val : expr), * $(,) ?) => { ... };
($order : ident ; $($val : expr), * $(,) ?) => { ... };
($order : path ; $($val : expr), * $(,) ?) => { ... };
($($val : expr), * $(,) ?) => { ... };
($order : ident, $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 ; $len : expr) => { ... };
}
Expand description
Constructs a BitArray
wrapper out of a literal array in source code, like
bits!
As with all macro constructors, bitarr!
can be invoked with either a sequence
of individual bit expressions (expr, expr
) or a repeated bit (expr; count
).
Additionally, the bit-ordering and element type can be provided as optional
prefix arguments.
The produced value is of type BitArray<O, [T; N]>
, and is subject to
[BitArray
]’s restricitons of element T
length N
. For instance, attempting
to produce a bit array that fills more than 32 T
elements will fail.
In addition, bitarr!
can be used to produce a type name instead of a value by
using the syntax bitarr!(for N [, in [O,] T])
. This syntax allows the
production of a monomorphized BitArray<O, V>
type that is capable of holding
N
bits. It can be used to type static sites such as struct
fields and
const
or static
declarations, and in these positions must specify both type
arguments as well as the length. It can also be used to type let
-bindings, but
as type inference is permitted here, it is less useful in this position.
Examples
use bitvec::prelude::*;
bitarr![Msb0, u8; 0, 1];
bitarr![Msb0; 0, 1];
bitarr![0, 1];
bitarr![0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0];
bitarr![Msb0, u8; 1; 5];
bitarr![1; 5];
This example shows how the for N, in O, T
syntax can be used to type locations
that cannot use inference:
use bitvec::prelude::*;
struct ContainsBitfield {
data: bitarr!(for 10, in Msb0, u8),
}
fn zero() -> ContainsBitfield {
ContainsBitfield { data: bitarr![Msb0, u8; 0; 10] }
}
The order/store type parameters must be repeated in the macros to construct both the typename and the value. Mismatches will result in a compiler error.