Use cases for const BTreeMap methods?

With the stabilization of const methods new, len, and is_empty for BTreeMap in 1.66.0, I'm curious about the intended use cases when we can't directly populate a const BTreeMap at compile time.

  • Are there ways to populate a const BTreeMap I'm overlooking?
  • Are the current const methods primarily meant to work in conjunction with future language features?

Not sure about the others, but const new is useful for putting a BTreeMap in a static:

static FOO: Mutex<BTreeMap<i32, String>> = Mutex::new(BTreeMap::new());

(since Rust doesn’t have runtime initializers for static variables).

3 Likes

The proposed future feature for populating a BTreeMap at compile time is:

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.