Rust FreezeBox: a deref'able lazy-initialized container.
FreezeBox<T>
is a container that can have two possible states:
- uninitialized: deref is not allowed.
- initialized: deref to a
&T
is possible.
To upgrade a FreezeBox
to the initialized state, call lazy_init
.
lazy_init
does not require a mutable reference, making FreezeBox
suitable for sharing objects first and initializing them later.
Attempting to lazy_init
more than once, or deref while uninitialized
will cause a panic.
Example:
This example creates a shared data structure, then circles back to initialize one member.
use FreezeBox;
use Arc;
let resources = new;
let res2 = resources.clone;
let func = move || ;
resources.name.lazy_init;
func;
Not quite what you were looking for?
There are many similar crates out there: