pub struct ColdInitLazyLock<T, F = fn() -> T> { /* private fields */ }Expand description
A lazy value that keeps initialization in a separate cold function.
Construct it with an initializer and dereference it to access the value.
Initialization runs once; concurrent callers wait, and an initializer panic
poisons the value, following LazyLock.
§Example
use tvm_ffi::extra::cold_init_lazy_lock::ColdInitLazyLock;
static NAME: ColdInitLazyLock<String> = ColdInitLazyLock::new(|| "ready".into());
assert_eq!(NAME.as_str(), "ready");§Why avoid inlining initialization?
Inlining initialization can enlarge the caller’s stack frame even when the value is already initialized. We keep initialization in a separate cold function and inline only the initialized check.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T, F = fn() -> T> !Freeze for ColdInitLazyLock<T, F>
impl<T, F> RefUnwindSafe for ColdInitLazyLock<T, F>
impl<T, F> Send for ColdInitLazyLock<T, F>
impl<T, F> Sync for ColdInitLazyLock<T, F>
impl<T, F> Unpin for ColdInitLazyLock<T, F>
impl<T, F> UnsafeUnpin for ColdInitLazyLock<T, F>where
T: UnsafeUnpin,
F: UnsafeUnpin,
impl<T, F> UnwindSafe for ColdInitLazyLock<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more