Debian Codegraph @

debian/rust-vendor/bitvec/doc/domain/Domain.md

raw
1 # Bit-Slice Element Partitioning
2
3 This structure provides the bridge between bit-precision memory modeling and
4 element-precision memory manipulation. It allows a bit-slice to provide a safe
5 and correct view of the underlying memory elements, without exposing the values,
6 or permitting mutation, of bits outside a bit-slice’s control but within the
7 elements the bit-slice uses.
8
9 Nearly all memory access that is not related to single-bit access goes through
10 this structure, and it is highly likely to be in your hot path. Its code is a
11 perpetual topic of optimization, and improvements are always welcome.
12
13 This is essentially a fully-decoded `BitSpan` handle, in that it addresses
14 memory elements directly and contains the bit-masks needed to selectively
15 interact with them. It is therefore by necessity a large structure, and is
16 usually only alive for a short time. It has a minimal API, as most of its
17 logical operations are attached to `BitSlice`, and merely route through it.
18
19 If your application cannot afford the cost of repeated `Domain` construction,
20 please [file an issue][0].
21
22 ## Memory Model and Variants
23
24 A given `BitSlice` has essentially two possibilities for where it resides in
25 real memory:
26
27 - it can reside entirely in the interior of a exactly one memory element,
28 touching neither edge bit, or
29 - it can touch at least one edge bit of zero or more elements.
30
31 These states correspond to the `Enclave` and `Region` variants, respectively.
32
33 When a `BitSlice` has only partial control of a given memory element, that
34 element can only be accessed through the bit-slice’s provenance by a
35 [`PartialElement`] handle. This handle is an appropriately-guarded reference to
36 the underlying element, as well as mask information needed to interact with the
37 raw bits and to manipulate the numerical contents. Each `PartialElement` guard
38 carries permissions for *its own bits* within the guarded element, independently
39 of any other handle that may access the element, and all handles are
40 appropriately synchronized with each other to prevent race conditions.
41
42 The `Enclave` variant is a single `PartialElement`. The `Region` variant is more
43 complex. It has:
44
45 1. an optional `PartialElement` for the case where the bit-slice only partially
46 occupies the lowest-addressed memory element it governs, starting after
47 bit-index 0 and extending up to the maximal bit-index,
48 1. a slice of zero or more fully-occupied memory elements,
49 1. an optional `PartialElement` for the case where it only partially occupies
50 the highest-addressed memory element it governs, starting at bit-index 0 and
51 ending before the maximal.
52
53 ## Usage
54
55 Once created, match upon a `Domain` to access its fields. Each `PartialElement`
56 has a [`.load_value()`][`PartialElement::load_value`] method that produces its
57 stored value (with all ungoverned bits cleared to 0), and a `.store_value()`
58 that writes into its governed bits. If present, the fully-occupied slice can be
59 used as normal.
60
61 [0]: https://github.com/bitvecto-rs/bitvec/issues/new
62 [`PartialElement`]: crate::domain::PartialElement
63 [`PartialElement::load_value`]: crate::domain::PartialElement::load_value