#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

#1327 in Rust patterns

Download history 334/week @ 2024-11-03 10/week @ 2024-11-10 175/week @ 2024-11-17

519 downloads per month
Used in 5 crates (via teo-runtime)

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