• Home
Name Date Size #Lines LOC

..--

examples/04-Jul-2025-311248

src/04-Jul-2025-8,8094,388

.android-checksum.jsonD04-Jul-20251.7 KiB11

.cargo-checksum.jsonD04-Jul-20251.3 KiB11

Android.bpD04-Jul-2025962 4036

Cargo.lockD04-Jul-20256.9 KiB276243

Cargo.tomlD04-Jul-20251.3 KiB6555

LICENSED04-Jul-2025903 2014

METADATAD04-Jul-2025358 1817

MODULE_LICENSE_ZLIBD04-Jul-20250

README.mdD04-Jul-20251.6 KiB5138

RELEASES.mdD04-Jul-20254.6 KiB14892

build.rsD04-Jul-2025556 1814

cargo_embargo.jsonD04-Jul-202529 33

README.md

1# slotmap
2
3A Rust library providing three containers with persistent unique keys to access
4stored values, `SlotMap`, `HopSlotMap` and `DenseSlotMap`. Upon insertion a key
5is returned that can be used to later access or remove the values. Insertion,
6deletion and access all take O(1) time with low overhead. Great for storing
7collections of objects that need stable, safe references but have no clear
8ownership otherwise, such as game entities or graph nodes. Two secondary maps,
9`SecondaryMap` and `SparseSecondaryMap` are also provided that allow you to map
10further objects to the keys created by one of the slot maps. Please refer to
11[**the documentation**](https://docs.rs/slotmap) for more information.
12
13The minimum required stable Rust version for `slotmap` is 1.49. To start using
14`slotmap` add the following to your `Cargo.toml`:
15
16```toml
17[dependencies]
18slotmap = "1.0"
19```
20
21# Example
22
23A short example:
24
25```rust
26use slotmap::{SlotMap, SecondaryMap};
27
28let mut sm = SlotMap::new();
29let foo = sm.insert("foo");  // Key generated on insert.
30let bar = sm.insert("bar");
31assert_eq!(sm[foo], "foo");
32assert_eq!(sm[bar], "bar");
33
34sm.remove(bar);
35let reuse = sm.insert("reuse");  // Space from bar reused.
36assert_eq!(sm.contains_key(bar), false);  // After deletion a key stays invalid.
37
38let mut sec = SecondaryMap::new();
39sec.insert(foo, "noun");  // We provide the key for secondary maps.
40sec.insert(reuse, "verb");
41
42for (key, val) in sm {
43    println!("{} is a {}", val, sec[key]);
44}
45```
46
47# License
48
49`slotmap` is released under the Zlib license, a permissive license. It is
50OSI and FSF approved and GPL compatible.
51