Safe, yes, but I don’t think the widespread use of syntactic elements like !, | and & is beautiful.
Rust beauty is about making hardware do exactly what you want, and not about expressing mathematicalish abstractions as crisply as you want. Both kinds of beauties are valid, but the second one is just not a goal of Rust.
Rust is relatively sigil-heavy, because it needs to express distinction between owned, shared and exclusive access, which for a higher level language all are just values.
Of course it would be better if we could have both, but it doesn’t seem possible with our current level of programming language technology.
I don’t know exactly what xyproto was thinking would be better, but perhaps words over symbols?
It looks quite like a lot of ‘line noise’ to me too, but I think that’s just because I’ve not been immersed in Rust. I thought the same about Elixir until I’d used it for a couple of months.
Short and expressive. Nice! I plan to share this with my C++ devs in the next days.
Why not just use an atomic for the second example?
It’s rather “why integer counter, instead some more real world data structure?”, as I wanted to show mutex specifically.
Similar point can be made about atomics: Rust allows non-atomic load at the end, but requires atomic loads from other threads. But I felt that a mutex is a better illustration because it is more boring, and because it shows nice RAII guard API.
The second example extends to any data type.