File: macros.md

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (31 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Constructor Macros

This module provides macros that can be used to create `bitvec` data buffers at
compile time. Each data structure has a corresponding macro:

- `BitSlice` has [`bits!`]
- `BitArray` has [`bitarr!`] (and [`BitArr!`] to produce type expressions)
- `BitBox` has [`bitbox!`]
- `BitVec` has [`bitvec!`]

These macros take a sequence of bit literals, as well as some optional control
prefixes, and expand to code that is generally solvable at compile-time. The
provided bit-orderings `Lsb0` and `Msb0` have implementations that can be used
in `const` contexts, while third-party user-provided orderings cannot be used in
`const` contexts but almost certainly *can* be const-folded by LLVM.

The sequences are encoded into element literals during compilation, and will be
correctly encoded into the target binary. This is even true for targets with
differing byte-endianness than the host compiler.

See each macro for documentation on its invocation syntax. The general pattern
is `[modifier] [T, O;] bits…`. The modifiers influence the nature of the
produced binding, the `[T, O;]` pair provides type parameters when the default
is undesirable, and the `bits…` provides the actual contents of the data
buffer.

[`BitArr!`]: macro@crate::BitArr
[`bitarr!`]: macro@crate::bitarr
[`bitbox!`]: macro@crate::bitbox
[`bits!`]: macro@crate::bits
[`bitvec!`]: macro@crate::bitvec