Trait std::sys_common::lazy_box::LazyInit
source · pub(crate) trait LazyInit {
// Required method
fn init() -> Box<Self>;
// Provided methods
fn cancel_init(x: Box<Self>) { ... }
fn destroy(_: Box<Self>) { ... }
}
Required Methods§
sourcefn init() -> Box<Self>
fn init() -> Box<Self>
This is called before the box is allocated, to provide the value to move into the new box.
It might be called more than once per LazyBox, as multiple threads
might race to initialize it concurrently, each constructing and initializing
their own box. All but one of them will be passed to cancel_init
right after.
Provided Methods§
sourcefn cancel_init(x: Box<Self>)
fn cancel_init(x: Box<Self>)
Any surplus boxes from init()
that lost the initialization race
are passed to this function for disposal.
The default implementation calls destroy().