Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lacking explanation of mutable globals (static mut alternatives) #4104

Open
kornelski opened this issue Nov 17, 2024 · 0 comments
Open

Lacking explanation of mutable globals (static mut alternatives) #4104

kornelski opened this issue Nov 17, 2024 · 0 comments

Comments

@kornelski
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant