I want to know what is the idiomatic way to create a constant Hashmap with values in Rust?
I have an implementation like:
const LOOKUP_TABLE: HashMap<usize, f64> = HashMap::from([
(1, 1.1), // Values are randomly put
(2, 2.2),
]);
and I get an error:
error[E0015]: cannot call non-const fn `<HashMap<usize, f64> as From<[(usize, f64); 12]>>::from` in constants
-->
|
18 | const LOOKUP_TABLE: HashMap<usize, f64> = HashMap::from([
| _________________________________________________^
19 | | (1, 1.1),
20 | | (2, 2.2),
31 | | ]);
| |__^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants