[−][src]Macro bitvec::bitvec
Construct a BitVec
out of a literal array in source code, like vec!
.
bitvec!
can be invoked in a number of ways. It takes the name of a Cursor
implementation, the name of a BitStore
-implementing fundamental, and zero or
more fundamentals (integer, floating-point, or boolean) which are used to build
the bits. Each fundamental literal corresponds to one bit, and is considered to
represent 1
if it is any other value than exactly zero.
bitvec!
can be invoked with no specifiers, a Cursor
specifier, or a Cursor
and a BitStore
specifier. It cannot be invoked with a BitStore
specifier but
no Cursor
specifier, due to overlap in how those tokens are matched by the
macro system.
Like vec!
, bitvec!
supports bit lists [0, 1, …]
and repetition markers
[1; n]
.
Notes
The bit list syntax bitvec![expr, expr, expr...]
currently produces an
&[bool]
slice of the initial pattern, which is written into the final
artifact’s static memory and may consume excessive space.
The repetition syntax bitec![expr; count]
currently zeros its allocated buffer
before setting the first count
bits to expr
. This may result in a
performance penalty when using bitvec![1; N]
, as the allocation will be zeroed
and then a subset will be set high.
This behavior is currently required to maintain compatibility with serde
expectations that dead bits are zero. As the serdes
module removes those
expectations, the repetition syntax implementation may speed up.
Examples
use bitvec::prelude::*; bitvec![BigEndian, u8; 0, 1]; bitvec![LittleEndian, u8; 0, 1,]; bitvec![BigEndian; 0, 1]; bitvec![LittleEndian; 0, 1,]; bitvec![0, 1]; bitvec![0, 1,]; bitvec![BigEndian, u8; 1; 5]; bitvec![LittleEndian; 0; 5]; bitvec![1; 5];