In the year of our Lord and Saviour 2024, Rust - the language that promised to save us from the scourge of writing C - still doesn't allow to declare and initialise a static variable. Just because.
Instead of a robust systems programming tool, all we got is a retarded JavaScript on steroids. So much disappointment.
@icon_of_computational_sin
You can declare a variable with static lifetime, but having a static variable in C sense, considering the borrow checker, would be kinda against the design of the language, you can still do that, but as the compiler can't guarantee thread safety, all modifications to the value of such a variable would have to happen in unsafe block: https://doc.rust-lang.org/reference/items/static-items.html
@m0xee lol indeed.
Now, do you know what's the one kind of data that absolutely should be both mutable and shared, which goes against Rust philosophy? Fucking mutexes! And also every other kind of synchronisation primitive.
My post was inspired by kernel people complaining literally about this.
@icon_of_computational_sin
Rust gives you an option to not think about it — like at all: you can have a bottle of vodka in you and just rely on the data types that are being copied — the compiler would tell you to go home and get some sleep if you attempt real silly shit. Slow, takes lots of resources? Well, you can work on that when and if you have time. Want to use mutex in your multi-threaded code? Try one of those Arc<Mutex<T>> ones, they are guaranteed to be atomic, therefore thread-safe.
@icon_of_computational_sin
Rust doesn't allow using static variables — that's a lie: it does! And compatibility with C code is even mentioned as primary use case in the docs. It doesn't make it easy? That's right — it's against its design goals: eliminating potentially unsafe code where it's possible. So what is even your point?
@icon_of_computational_sin
Still not enough, wanna do it real cowboy style like they did in the good old days with C? Then surely, using the "unsafe" keyword to make that pesky compiler shut the fuck up won't be a problem! It gives you choice — write safe code and optimise just the parts that are critical by resorting to potentially unsafe code, that's good, right?