Creating a const BTreeMap of const array containing subarrays

Out of an const array with subarrays (where each item is a (usize, TestEnum) tuple)...

#[derive(Debug)]
enum TestEnum {
     AAA(bool),
     BBB,
}

const ARRAY: &[(usize, &[TestEnum])] = &[
     (0, &[TestEnum::AAA(true), TestEnum::BBB]), 
     (1, &[TestEnum::BBB])
];

dgb!(ARRAY); // works fine!

...I'm trying to create a BTreeMap as below:

const BTREE: &BTreeMap<i32, &[PathSegment]> = &BTreeMap::from(ARRAY);

However, the the compiler is complaining:
the trait From<&[(usize, &[TestEnum])]>is not implemented forBTreeMap<_, _, _>`

Before I jump into the water of trying to implement the missing From trait:

  1. Is there a way to construct the const BTreeMap other than via the array of &-s that I am using above?
  2. If not 1, is it even possible to create such a const BTreeMap at all...?
  3. If i do need to implement the missing From trait, could you give me an assistance of where to start?

Other ideas?

You can't allocate in a const.

3 Likes
2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.