orlp / slotmap

Slotmap data structure for Rust
zlib License
1.13k stars 70 forks source link

Reuse keys across maps #9

Closed MaikKlein closed 6 years ago

MaikKlein commented 6 years ago

For example:

let mut create: SlotMap<CreateFoo> = SlotMap::new();
let key = create.insert(something);
let foo_map: SlotMap<Foo> = create.map(|create| Foo::new(create)); // reuse the keys from `create`
foo_map.get(key); // should work

Is something like this currently possible?

orlp commented 6 years ago

SlotMap implements the Clone trait. So your example is simply:

let mut create: SlotMap<CreateFoo> = SlotMap::new();
let key = create.insert(something);
let foo_map: SlotMap<Foo> = create.clone(); // reuse the keys from `create`
foo_map.get(key); // should work