Skip to main content

Module managed

Module managed 

Source
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

RoleTypedType-erased
owns the valueManagedDynamicManaged
shared handleManagedRefDynamicManagedRef
exclusive handleManagedRefMutDynamicManagedRefMut
unclaimed handleManagedLazyDynamicManagedLazy

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§

gc
Value boxes that tolerate reference cycles.
value
One enum over every way a value can be held.

Structs§

DynamicManaged
Owner of a value whose type is only known at runtime.
DynamicManagedLazy
Unclaimed handle to a value whose type is only known at runtime.
DynamicManagedRef
Shared handle to a value whose type is only known at runtime.
DynamicManagedRefMut
Exclusive handle to a value whose type is only known at runtime.
Managed
Owner of a value plus its runtime borrow state.
ManagedLazy
Unclaimed handle to a value owned by a Managed.
ManagedRef
Shared handle to a value owned by a Managed, the runtime &T.
ManagedRefMut
Exclusive handle to a value owned by a Managed, the runtime &mut T.