Expand description
§sefer-region — typed handle-addressed store
A thin typed membrane over slotmap: values live
in slotmap’s dense, cache-friendly, always-compact backing store, and every
operation exposes only typed Handle<T> values — raw DefaultKeys never
escape the crate boundary.
§What makes this different from using slotmap directly?
Slotmap’s DefaultKey is untyped: a DefaultKey from one map can be passed
to another of a different value type without a compile error. sefer-region
wraps it in Handle<T> — a PhantomData<fn() -> T>-branded key — so the
compiler rejects cross-region handle confusion at the type level.
§Invariants upheld (I1–I5)
- I1 — resolution: a fresh handle resolves via
Region::getto the inserted value until it isRegion::removed. - I2 — tombstone: after
remove(h),get(h)isNoneforever; a secondremove(h)is a no-opNone. - I3 — no ABA: a stale handle — one whose slot has since been reused —
never resolves to a live value. slotmap’s
DefaultKeycarries a generation that is bumped on removal, so the old handle fails the version check. - I4 — accounting:
Region::lenequals the number of live entries andRegion::is_emptyagrees. - I5 — drop-once: every live value is dropped exactly once — on
remove(returned to the caller) or onRegiondrop — never twice, never leaked.
§Pure Rust / zero own unsafe
#![forbid(unsafe_code)] at the top of this crate. The internal unsafe in
the slotmap dependency is its own, audited and battle-tested. This crate
adds no C / C++ libraries and contributes zero unsafe blocks of its own.
§no_std support
With default-features = false (disabling std) the crate compiles under
no_std + alloc, providing Region<T> and Handle<T>. The std
feature (on by default) additionally enables SyncRegion<T>, which wraps
Region<T> in std::sync::RwLock.
Structs§
- Handle
- An opaque, copyable reference to a value stored in a
Region. - Region
- A handle-addressed store of
T. - Sync
Region - A thread-safe wrapper around
Region<T>— the trusted concurrent baseline.