3 ms·
"Set once and only once" is achieved well via Rust's OnceLock [1], and it's a pattern I use quite heavily in my Rust code. Especially because OnceLock only requ
by sunshowers 2y ago
"Set once and only once" is achieved well via Rust's OnceLock [1], and it's a pattern I use quite heavily in my Rust code. Especially because OnceLock only requires a shared reference and not a mutable one. It's a really good fit for cached results computed on-demand, scoped to whatever level is reasonable (individual type, thread, or whole process).
[1] https://doc.rust-lang.org/beta/std/sync/struct.OnceLock.html https://doc.rust-lang.org/beta/std/sync/struct.OnceLock.html