const THING: Mutex<u64> = Mutex::new(4);
without using the once_cell crate. This is pretty cool! Also I realize that the Rust playground is still using 1.62.0https://play.rust-lang.org/?version=beta&mode=debug&edition=...
const THING: Mutex<u64> = Mutex::new(4);
without using the once_cell crate. This is pretty cool! Also I realize that the Rust playground is still using 1.62.0https://play.rust-lang.org/?version=beta&mode=debug&edition=...
The playground rebuilds overnight (roughly after the nightly is released); releases don’t have as fixed timing so I tend to trigger a rebuild when I notice. This HN post was delivered before the git tag was published even, so I’ve started it.
Playground is updated now.
This might be what you want if you, for some reason, need to make different Mutexes with a 4 in them all the time. But, if you actually meant one Mutex, which intially has a 4 in it, then that's a static variable not a constant.
https://play.rust-lang.org/?version=beta&mode=debug&edition=...
Change FOUR to be static instead of const, and now when we print y each time it's gone up by ten because we're using the same Mutex which is what we presumably intended.