Expand description

The methods and macros provided directly in this index_map module (new, with_capacity) work in both std and no-std modes - unlike the corresponding methods on IndexMap itself.

Unfortunately IndexMap is very hard to use from no-std (see docs and relevant github issue). It uses a weird build flag to detect if no-std is present, which is hard to force unless you explicitly do eg a WASM build and see that it’s missing.

The recommended way to use IndexMap is to add use sbor::rust::collections::* and then reference the type inline as index_map::IndexMap and create new sets using index_map::new, index_map::with_capacity, or the index_map::indexmap! macro. Always putting the index_map mod will help enforce the use of these methods instead of the methods on IndexMap itself.

You can use these exports as follows:

use sbor::rust::collections::*;

let index_map: IndexMap<K, V> = index_map_new();
let index_map: IndexMap<K, V> = index_map_with_capacity(n);
let index_map = indexmap!(1u32 => "entry_one", 5u32 => "entry_two");

Macros§

Functions§

  • This is safe for std and no-std use cases (unlike IndexMap::new which disappears when std is not in the toolchain - see this article for deep technical reasons)
  • This is safe for std and no-std use cases (unlike IndexMap::with_capacity which disappears when std is not in the toolchain - see this article for deep technical reasons)

Type Aliases§