Re:Cursed Linear Types in Rust
by sunshowers on Sunday December 01, 2024 @06:51PM
(#42291687)
"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