1 stable release

1.0.2 Apr 18, 2021

#1171 in Data structures

Download history 14/week @ 2024-03-11 13/week @ 2024-03-18 30/week @ 2024-03-25 50/week @ 2024-04-01 10/week @ 2024-04-08 19/week @ 2024-04-15 22/week @ 2024-04-22 10/week @ 2024-04-29 18/week @ 2024-05-06 21/week @ 2024-05-13 9/week @ 2024-05-20 19/week @ 2024-05-27 10/week @ 2024-06-03 17/week @ 2024-06-10 10/week @ 2024-06-17 19/week @ 2024-06-24

57 downloads per month
Used in 7 crates (via otter-support)

Zlib license


This is a fork

The original is here: https://github.com/orlp/slotmap

This fork exists only because https://github.com/orlp/slotmap/issues/55 and https://github.com/orlp/slotmap/pull/56 remain un-reviewed upstream.

The git source for this fork is here: https://github.com/ijackson/slotmap/tree/slotmap-fork-otter


A Rust library providing three containers with persistent unique keys to access stored values, SlotMap, HopSlotMap and DenseSlotMap. Upon insertion a key is returned that can be used to later access or remove the values. Insertion, deletion and access all take O(1) time with low overhead. Great for storing collections of objects that need stable, safe references but have no clear ownership otherwise, such as game entities or graph nodes. Two secondary maps, SecondaryMap and SparseSlotMap are also provided that allow you to map further objects to the keys created by one of the slot maps. Please refer to the the documentation for more information.

The minimum required stable Rust version for slotmap is 1.49. To start using slotmap add the following to your Cargo.toml:

slotmap = "1.0"


A short example:

use slotmap::{SlotMap, SecondaryMap};

let mut sm = SlotMap::new();
let foo = sm.insert("foo");  // Key generated on insert.
let bar = sm.insert("bar");
assert_eq!(sm[foo], "foo");
assert_eq!(sm[bar], "bar");

let reuse = sm.insert("reuse");  // Space from bar reused.
assert_eq!(sm.contains_key(bar), false);  // After deletion a key stays invalid.

let mut sec = SecondaryMap::new();
sec.insert(foo, "noun");  // We provide the key for secondary maps.
sec.insert(reuse, "verb");

for (key, val) in sm {
    println!("{} is a {}", val, sec[key]);


slotmap is released under the Zlib license, a permissive license. It is OSI and FSF approved and GPL compatible.