Re:Notes on a Smaller Rust
by steveklabnik on Thursday July 18, 2019 @10:21AM
(#20470049)
We took the closure syntax from Ruby/Smalltalk, and the lifetime syntax from OCaml.
On &mut a vs. mut &a, when read literally left to right the former is “a reference to a mutable a” and the latter is “a mutable reference to a”
I'm guessing the &mut a stuff makes more sense to C folks. In C you have to deal with const, and it can go anywhere. A const pointer to a non-const item, a pointer to const value, etc. That's my guess anyway.
I'm trying to learn Rust, working through various programming exercises, but it looks and feels very foreign to me.
One example is the closure syntax. Compared to Go where closures look just like function definitions, closures in Rust look needlessly complex.
I also always find myself wanting to type mut &a instead of the correct &mut a. The former just seems more obvious to me, a reference to a is &a. Mutable a is mut a. So a mutable reference must be mut &a.
Then the lifetime syntax, I don't even know what to think of that, but that's probably more because I'm struggling asking myself "Should I use a lifetime here, or am I doing something else wrong that is preventing the compiler from figuring it out."
Maybe these things make more sense to people coming from C.