lateinit
Disclaimer: this crate breaks Rust's safety guarantees. You should probably be using spin::Once
,
std::sync::Once
, or
lazy_static
instead. If you're sure you
want zero-cost late initialization at the cost of safety, read on.
[]
= "0.1"
The LateInit
type provides an unsafe interface for initializing static variables at runtime.
Design goals for this crate are to provide checked, one-time initialization and unchecked, zero-cost
access thereafter.
static SOMETHING: = new;
This crate should be used sparingly and carefully—it breaks Rust's safety guarantees.
It's on you to ensure that you initialize your LateInit
s before accessing. Bad things™ will
happen otherwise. It's heavily suggested that you initialize only in a clearly demarcated region
of setup code.
Features
#[no_std]
is supported.
By default, init
asserts that it hasn't been called before, and there are debug_assert
s in
the Deref
and AsRef
implementations to catch potential errors while testing. If for some
reason you want to turn these safety measures off, you can enable the unchecked
feature flag
and they will be compiled out.