3 ms·
Wouldn’t you want to use static instead of const, otherwise you might get a new unique mutex at each usage? I think there’s a Clippy lint for that. The playgr
by shepmaster 4y ago
Wouldn’t you want to use static instead of const, otherwise you might get a new unique mutex at each usage? I think there’s a Clippy lint for that.
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.
- tialaramex 4y agoYes. If I say FOUR is a const Mutex with a 4 in it, whenever I talk about FOUR I get a completely new unlocked Mutex with a 4 in it, unrelated to any other Mutex regardless of whether it was made the same way. 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=2021&gist=6639e3f2e7cdc6ae18b47b19ea2ccec2 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.
- baby 4y agoWhat's the difference between CONST and STATIC fundamentally?
- notpopcorn 4y agoA const is like a `#define` in C or C++, while a static is a global variable.
- CryZe 4y agoIf those terms mean anything to you: const is an rvalue, static is an lvalue.