3 releases
0.0.3 | Feb 15, 2023 |
---|---|
0.0.2 | Feb 3, 2023 |
0.0.1 | Jan 8, 2023 |
#1331 in Rust patterns
39 downloads per month
91KB
1.5K
SLoC
Dungeon Cell
A cell type that can store any static type, no allocations required.
This crate is #![no_std]
.
lib.rs
:
Dungeon Cell
Cell and Cell-like types that can store any static type without dynamic memory.
Currently only the core primitive is implemented (unsized, cell, stack vec, ... are in progress).
Example
use dungeon_cell::{DungeonCore, layout_for};
let mut c: DungeonCore<layout_for!(i32, f64)> = DungeonCore::new();
// we can store a i32 and get it back
c.store(1234);
assert_eq!(c.take::<i32>(), Some(1234));
// we can store a f64 and get it back
c.store(1.234);
assert_eq!(c.take::<f64>(), Some(1.234));
// we can't take a type the core isn't storing
c.store(1234);
assert_eq!(c.take::<f64>(), None);
// we can borrow both unique and shared
c.store(1234);
*c.borrow_mut::<i32>().unwrap() += 10;
assert_eq!(c.borrow::<i32>(), Some(&1244));
Dependencies
~215KB