pub struct Lazy<T, F = fn() -> T> { /* private fields */ }Expand description
A value built by F on first access.
Built on OnceCell::get_or_init_racy: threads that reach an
unbuilt Lazy at the same moment each run F, one result is kept and
the others are dropped, and nobody waits for anybody. F therefore
runs at least once and possibly more than once, so it is Fn and
should be free of side effects that must not repeat.
use nuclei::sync::Lazy;
static TABLE: Lazy<Vec<u32>> = Lazy::new(|| (0..4).collect());
assert_eq!(TABLE.len(), 4);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T, F = fn() -> T> !Freeze for Lazy<T, F>
impl<T, F = fn() -> T> !RefUnwindSafe for Lazy<T, F>
impl<T, F = fn() -> T> !UnwindSafe for Lazy<T, F>
impl<T, F> Send for Lazy<T, F>
impl<T, F> Sync for Lazy<T, F>
impl<T, F> Unpin for Lazy<T, F>
impl<T, F> UnsafeUnpin for Lazy<T, F>where
F: UnsafeUnpin,
T: UnsafeUnpin,
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