| Crates.io | overlay-map |
| lib.rs | overlay-map |
| version | 0.2.2 |
| created_at | 2025-04-04 22:36:06.092241+00 |
| updated_at | 2025-04-07 16:59:55.84478+00 |
| description | A two-layered map data structure for Rust that tracks current and previous values for each key โ with zero-clone, in-place state transitions. |
| homepage | https://github.com/jameslkingsley/overlay-map |
| repository | https://github.com/jameslkingsley/overlay-map |
| max_upload_size | |
| id | 1620886 |
| size | 191,097 |
overlay-map is a two-layered map data structure for Rust that tracks current and previous values for each key โ with zero-clone, in-place state transitions.
It provides OverlayMap<K, V>, a map where each value is an Overlay<V>: a compact two-slot container that allows pushing, swapping, and pulling values without cloning or heap allocation.
push, the current foreground is moved to backgroundpush_if)Overlay<T> usable independently from the mapOverlayMap<K, V>A map-like wrapper for managing per-key two-layered state.
Overlay<T>A standalone container that tracks two versions of a value:
fg โ the current valuebg โ the previous value (optional)Uses zero-copy, branchless slot flipping via raw memory and bitflags.
use overlay_map::Overlay;
fn main() {
let mut door = Overlay::new_fg("Alice");
println!("Present: {:?}, {:?}", door.fg(), door.bg());
for name in ["Bob", "Carol", "Dave", "Eve"] {
if let Some(evicted) = door.swap(name) {
println!("{evicted} left");
}
println!("Present: {:?}, {:?}", door.bg(), door.fg());
}
while let Some(pulled) = door.pull() {
println!("{pulled} left");
}
println!("Present: {:?}, {:?}", door.bg(), door.fg());
}
Overlay<T> uses [MaybeUninit<T>; 2] with a compact bitflag for presence and slot state.Option<T>, no clone required.push, pull, swap are in-place and branch-minimal.overlay-map is ideal for:
Overlay<T> vs Option<(T, Option<T>)>These benchmarks measure the performance of the push operation in both the
Overlay<T> and a conventional tuple-based implementation. Recorded on a
MacBook Air M4.
Overlay.These graphs were generated using Criterion.rs and represent measured runtime distribution and scaling with iteration count.
MIT
Contributions, bug reports, and feature ideas welcome.