|
1 anno fa | |
---|---|---|
.. | ||
benches | 1 anno fa | |
src | 1 anno fa | |
tests | 1 anno fa | |
Cargo.toml | 1 anno fa | |
README.md | 1 anno fa |
Generational Box is a runtime for Rust that allows any static type to implement Copy
. It can be combined with a global runtime to create an ergonomic state solution like dioxus-signals
. This crate contains no unsafe
code.
Three main types manage state in Generational Box:
Example:
use generational_box::{UnsyncStorage, AnyStorage};
// Create an owner for some state for a scope
let owner = UnsyncStorage::owner();
// Create some non-copy data, move it into a owner, and work with copy data
let data: String = "hello world".to_string();
let key = owner.insert(data);
// The generational box can be read from and written to like a RefCell
let value = key.read();
assert_eq!(*value, "hello world");
Internally, generational-box
creates an arena of generational RefCell
's that are recycled when the owner is dropped. You can think of the cells as something like &'static RefCell<Box<dyn Any>>
with a generational check to make recycling a cell easier to debug. Then GenerationalBox's are Copy
because the &'static
pointer is Copy