3 ms·
Another PITA is the lack of safe static variables.
by The_rationalist 7y ago
Another PITA is the lack of safe static variables.
- Rusky 7y agoRust does have safe static variables. You just need a) to use interior mutability (`static mut` is a very strange feature that should probably never have existed) and b) to ensure that its type is `Sync` (since multiple threads can obtain references to it). For example, use an atomic integer: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7a7b25d4ae9f10e2cede6ce13b5b5bf3 https://play.rust-lang.org/?version=stable&mode=debug&editio... You can also use types built on std::sync::Once and UnsafeCell, like once_cell::Lazy<std::sync::RwLock<T>>. This will get even easier as we get `const fn` constructors for locks in the future.
- The_rationalist 7y agoInteresting but this seems so unergonomic that I will still be virtually forced to not use static variables and thus loose their expressive power.
- kam 7y agoTry https://docs.rs/once_cell/ https://docs.rs/once_cell/