2 ms·
I disagree. Not all Rust code needs to be maximally generalized and reusable. If this were library code, I might feel differently. But here we're looking at cod
by mwcampbell 4y ago
I disagree. Not all Rust code needs to be maximally generalized and reusable. If this were library code, I might feel differently. But here we're looking at code for installing a global, system-wide keyboard hook. Using a global variable is a direct, pragmatic, no-nonsense way of doing it.
Edit: Further, there's no such thing as "the purpose of using Rust". Different users can use the same tool for different purposes, and Rust is no different.
- pizza234 4y agoThat's fair, but I seriously consider the danger of a slippery slope. To keep in mind, on a pragmatic level, that this type of global can be trivially implemented, at a minimum, via atomics, so the cost to avoid the unsafe is near-zero. Atomics are not supported by all the platforms, but based on my understanding of their targets (x86-64), they're supported.
- FreeFull 4y agoAt the very least, I would have used an AtomicBool rather than a static mut. See https://github.com/rust-lang/rust/issues/53639 https://github.com/rust-lang/rust/issues/53639 . As a bonus, AtomicBool doesn't require any unsafe code.