Skip to content

Commit bb95207

Browse files
197gwhitequark
authored andcommitted
Add a slot map implementation
A slot map is a linear container similar to a vector but the indices contain are invalidated when the element is removed, and can not (or are very unlikely to) incidentally refer to a valid element again even if new elements are inserted. This implementation differs from allocating slot maps as it does not prefer value semantics for inserting and removing elements but rather offers a reserve and remove interface based on mutable references. This makes it easier for a user to avoid dropping any instances as any initialization and de-initialization can be freely chosen to write or swap. This is important if instances may contain costly resources such as allocations that are hard to recover.
1 parent 313f791 commit bb95207

File tree

2 files changed

+496
-0
lines changed

2 files changed

+496
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ extern crate alloc;
1111

1212
mod object;
1313
mod slice;
14+
mod slotmap;
1415
#[cfg(feature = "map")]
1516
mod map;
1617

1718
pub use object::Managed;
1819
pub use slice::ManagedSlice;
20+
pub use slotmap::{
21+
Key as SlotKey,
22+
Slot as SlotIndex,
23+
SlotMap,
24+
};
1925
#[cfg(feature = "map")]
2026
pub use map::{ManagedMap,
2127
Iter as ManagedMapIter,

0 commit comments

Comments
 (0)