Debian Codegraph @

debian/rust-vendor/bitvec/doc/mem/elts.md

raw
1 # Bit Storage Calculator
2
3 Computes the number of `T` elements required to store some number of bits. `T`
4 must be an unsigned integer type and cannot have padding bits, but this
5 restriction cannot be placed on `const fn`s yet.
6
7 ## Parameters
8
9 - `bits`: The number of bits being stored in a `[T]` array.
10
11 ## Returns
12
13 A minimal `N` in `[T; N]` that is not less than `bits`.
14
15 As this is a `const` function, when `bits` is also a `const` expression, it can
16 be used to compute the size of an array type, such as
17 `[u32; elts::<u32>(BITS)]`.
18
19 ## Examples
20
21 ```rust
22 use bitvec::mem as bv_mem;
23
24 assert_eq!(bv_mem::elts::<u8>(10), 2);
25 assert_eq!(bv_mem::elts::<u8>(16), 2);
26
27 let arr: [u16; bv_mem::elts::<u16>(20)] = [0; 2];
28 ```