Expand description
Value boxes with runtime checked borrowing.
A managed box is an owner plus a Lifetime,
so handles to it can be handed to a script and still be checked at
runtime. When the owner goes away, every handle reports it instead of
dangling.
§The four roles
| Role | Typed | Type-erased |
|---|---|---|
| owns the value | Managed | DynamicManaged |
| shared handle | ManagedRef | DynamicManagedRef |
| exclusive handle | ManagedRefMut | DynamicManagedRefMut |
| unclaimed handle | ManagedLazy | DynamicManagedLazy |
The typed boxes know their Rust type at compile time. The dynamic ones
carry a TypeHash instead and check it on every access, which is what
script values use. into_dynamic and into_typed convert between them.
Two more shapes build on these: value wraps all roles in one enum, so
code can accept a value without caring how it is held, and gc adds
boxes that survive reference cycles.
let mut value = Managed::new(42);
let borrow = value.borrow().unwrap();
// a shared handle is out, so an exclusive one is refused
assert!(value.borrow_mut().is_none());
assert_eq!(*borrow.read().unwrap(), 42);Modules§
Structs§
- Dynamic
Managed - Owner of a value whose type is only known at runtime.
- Dynamic
Managed Lazy - Unclaimed handle to a value whose type is only known at runtime.
- Dynamic
Managed Ref - Shared handle to a value whose type is only known at runtime.
- Dynamic
Managed RefMut - Exclusive handle to a value whose type is only known at runtime.
- Managed
- Owner of a value plus its runtime borrow state.
- Managed
Lazy - Unclaimed handle to a value owned by a
Managed. - Managed
Ref - Shared handle to a value owned by a
Managed, the runtime&T. - Managed
RefMut - Exclusive handle to a value owned by a
Managed, the runtime&mut T.