Module cl_structures::index_map

source ·
Expand description

Trivially-copyable, easily comparable typed indices, and an IndexMap to contain them.

§Examples

// first, create a new MapIndex type (this ensures type safety)
make_intern_key!{
    NumbersKey
}

// then, create a map with that type
let mut numbers: IndexMap<i32, NumbersKey> = IndexMap::new();
let first = numbers.insert(1);
let second = numbers.insert(2);
let third = numbers.insert(3);

// You can access elements immutably with `get`
assert_eq!(Some(&3), numbers.get(third));
assert_eq!(Some(&2), numbers.get(second));
// or by indexing
assert_eq!(1, numbers[first]);

// Or mutably
*numbers.get_mut(first).unwrap() = 100000;

assert_eq!(Some(&100000), numbers.get(first));

Macros§

Structs§

Traits§