#set #defer #initialized #value #struct #deferred #box

deferred-box

Defer the value set after the struct has been initialized

5 releases

0.1.4 Nov 3, 2024
0.1.3 Nov 3, 2024
0.1.2 Nov 3, 2024
0.1.1 Nov 3, 2024
0.1.0 Nov 3, 2024

#1629 in Rust patterns

Download history 153/week @ 2024-10-28 191/week @ 2024-11-04 182/week @ 2024-11-18 17/week @ 2024-11-25 61/week @ 2024-12-02 65/week @ 2024-12-09

325 downloads per month
Used in 5 crates (2 directly)

MIT license

5KB
93 lines

Deferred Box

Defer the value set after the struct has been initialized.

Installation

Add these lines to Cargo.toml under the [dependencies] section:

deferred-box = "0.1"

Usage

let deferred_box = DeferredBox::new();
deferred_box.get(); // None
deferred_box.set(42);
deferred_box.get(); // Some(&42)
deferred_box.get_or_init(|| 0); // &42

License

MIT License

No runtime deps