#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

#1402 in Rust patterns

Download history 153/week @ 2024-10-28 191/week @ 2024-11-04

344 downloads per month

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