this post was submitted on 15 Nov 2025
6 points (100.0% liked)
Rust
7509 readers
17 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 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Another commenter already explained why this is unsound, so I'll skip that, though
static mutis almost universally unsound.Note, of course, that
main()won't be called more than once, so if you can, I would honestly just make this a stack variable containing aBox<[u8; 0x400]>instead. Alternatively, aBox<[u8]>can make it simpler to pass around, and aVec<u8>that is pre-allocated withVec::with_capacitylets you track the current length as well with the buffer (if it's going to have a variable length of actually useful data).If you want to make it a static for some reason, I'd recommend making it just
staticandthread_local, then wrapping it in some kind of cell. Making it thread local will mean you don't need to lock to access it safely.