You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In an error message about mutable global variables (rust-lang/rust#133143) I wanted to link to the book to a chapter explaining how to use static with mutable data, but I couldn't find one.
The closest one is about Mutex, but the chapter is written in the context of channels and non-global shared mutable state, which doesn't work as a reference for how to use static X: Mutex.
Despite global variables not being the best practice, I think a chapter dedicated to use of mutable statics is needed. Without guidance, users may discover static mut, which is even more problematic. It's not obvious that an "immutable" static can be used for mutable globals. Rust now has a new OnceLock that works for initialization of globals.
The text was updated successfully, but these errors were encountered:
In an error message about mutable global variables (rust-lang/rust#133143) I wanted to link to the book to a chapter explaining how to use
static
with mutable data, but I couldn't find one.The closest one is about
Mutex
, but the chapter is written in the context of channels and non-global shared mutable state, which doesn't work as a reference for how to usestatic X: Mutex
.Despite global variables not being the best practice, I think a chapter dedicated to use of mutable
static
s is needed. Without guidance, users may discoverstatic mut
, which is even more problematic. It's not obvious that an "immutable"static
can be used for mutable globals. Rust now has a newOnceLock
that works for initialization of globals.The text was updated successfully, but these errors were encountered: