docs.rs failed to build vslab-2.0.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
🚀 Features
- ⚡ O(1) Operations - Insert, remove, and access operations all run in constant time
- 🔑 Versioned Keys - Keys include version information to prevent stale data access
- 💾 Memory Efficient - Uses a free list to reuse memory of removed entries
- 🔧 Custom Key Types - Support for user-defined key types via the
SlabId
trait - 📦 Zero Dependencies - Core functionality uses only
std
- 🌐 WASM Support - Full support for WebAssembly targets
- 🛡️ Type Safe - Optional custom key types prevent mixing different key types
📦 Installation
Add this to your Cargo.toml
:
[]
= "*"
🎯 Basic Usage
use Slab;
// Create a slab with u64 keys and String values
let mut slab = default;
// Insert values and get unique keys
let apple_id = slab.insert;
let banana_id = slab.insert;
// Access values by key
assert_eq!;
assert_eq!;
// Remove a value
let removed = slab.remove.unwrap;
assert_eq!;
// The old key is now invalid (stale)
assert!;
// Insert a new value (reuses the old slot)
let orange_id = slab.insert;
assert_eq!;
🔧 Custom Key Types
For better type safety, you can define custom key types:
use ;
// Define a custom key type
new_type_id!;
let mut entities = default;
let player_id = entities.insert;
let enemy_id = entities.insert;
// Type safety: EntityId and u64 keys cannot be mixed
// let invalid: Slab<u64, String> = Slab::default();
// invalid.insert(player_id); // Compile error!
assert_eq!;
assert_eq!;
assert!;
🙏 Acknowledgments
- Inspired by the
slotmap
andslab
crates - Thanks to all contributors who have helped improve this crate
License
See LICENSE file.