Debian Codegraph @

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

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