this post was submitted on 23 Aug 2023
18 points (100.0% liked)
Rust
5974 readers
67 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
OnceLock is the wrong primitive for this. Use a Mutex or an RwLock instead? You can initialize either of them with an empty array at declaration, so you don't need the set_log function. In push_log, do a
.lock().unwrap()
for a mutex or.write().unwrap()
for an rwlock to get mutable access to the vector.Nice, thanks... looking into these now.