[][src]Crate lazyonce

Wrapper type for lazy initialization

Store "immutable" cell that computes its value once, when it's first accessed. Allows lazy initialization as an implementation detail, without need to expose any mutable methods.

It's like lazy_static, but not static. It's like std::sync::Once, but holds a value.

It's thread-safe (Send and Sync).

use lazyonce::LazyOnce;
struct Oracle {
    answer: LazyOnce<u32>,

impl Oracle {
    pub fn get_answer(&self) -> &u32 {
        self.answer.get(|| think()) // think() is called only once



Wrapper type for lazy initialization