pub(crate) trait LazyInit {
    // Required method
    fn init() -> Box<Self>;

    // Provided methods
    fn cancel_init(x: Box<Self>) { ... }
    fn destroy(_: Box<Self>) { ... }
}

Required Methods§

source

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§

source

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().

source

fn destroy(_: Box<Self>)

This is called to destroy a used box.

The default implementation just drops it.

Implementors§