Debian Codegraph @

debian/rust-vendor/bitvec/doc/field/BitField_store.md

raw
1 # Integer Storing
2
3 This method writes an integer into the contents of a bit-slice region. The
4 region may be shorter than the source integer type, in which case the stored
5 value will be truncated. On load, it may be zero-extended (unsigned destination)
6 or sign-extended from the most significant **stored** bit (signed destination).
7
8 The region may not be zero bits, nor wider than the source type. Attempting
9 to store a `u32` into a bit-slice of length 33 will panic the program.
10
11 ## Operation and Endianness Handling
12
13 The value to be stored is broken into segments according to the elements of the
14 bit-slice receiving it. If the bit-slice contains more than one element, then
15 the numerical significance of each segment routes to a storage element according
16 to the target’s endianness:
17
18 - little-endian targets consider each *`T` element* to have increasing numerical
19 significance, starting with the least-significant segment at the low address
20 and ending with the most-significant segment at the high address.
21 - big-endian targets consider each *`T` element* to have decreasing numerical
22 significance, starting with the most-significant segment at the high address
23 and ending with the least-significant segment at the low address.
24
25 See the documentation for [`.store_le()`] and [`.store_be()`] for more detail on
26 what this means for how the in-memory representation of bit-slices translates to
27 stored values.
28
29 You must always use the loading method that exactly corresponds to the storing
30 method previously used to insert data into the bit-slice: same suffix on the
31 method name (none, `_le`, `_be`) and same integer type. `bitvec` is not required
32 to, and will not, guarantee round-trip consistency if you change any of these
33 parameters.
34
35 ## Type Parameters
36
37 - `I`: The integer type being stored. This can be any of the signed or unsigned
38 integers.
39
40 ## Parameters
41
42 - `&self`: A bit-slice region whose length is in the range `1 ..= I::BITS`.
43 - `value`: An integer value whose `self.len()` least numerically significant
44 bits will be written into `self`.
45
46 ## Panics
47
48 This panics if `self.len()` is 0, or greater than `I::BITS`.
49
50 ## Examples
51
52 This method is inherently non-portable, and changes behavior depending on the
53 target characteristics. If your target is little-endian, see [`.store_le()`]; if
54 your target is big-endian, see [`.store_be()`].
55
56 [`.store_be()`]: Self::store_be
57 [`.store_le()`]: Self::store_le