> In Rust it's also obvious because every = is a move.
False, depending on the presence of an explicit type annotation on the left-hand side, an = triggers either a move or a reborrow.If you assume = always moves you can just never use automatic reborrowing (do &mut * instead) and you'll loose nothing.
I don't think that's a very common pattern, fully optional and it can be just treated as another exception to the rule, just like Copy types.
So that's total of two exceptions. Way easier to be tackled individually when the time comes than assuming = means something else, or something complex from the start.
> pub fn main() {
> let mut x = String::from("moo");
> let y = &mut x;
> let z = y;
> println!("{:?}", y)
> }
>
> pub fn main() {
> let mut x = String::from("moo");
> let y = &mut x;
> let z: &mut _ = y;
> println!("{:?}", y)
> }It's completely optional fearure. You don't have to rely on it. Like auto-insertion of semicolons in JS maybe it's better if you don't. Although likelihood of this biting you is way lower than in case of relying on semicolons autoinsertion.
My claim is that for most Rust users, understanding the borrow checker is limited to a few heuristics that seem to work for them 80% of the time, and throwing up their hands and declaring an approach unworkable the remaining 20% of the time. To a first approximation, no one can mentally model the borrow checker beyond extremely simple examples of 4-5 lines of code.
In Rust it's also obvious because every = is a move. Confusion comes from tutorials pretending for too long that it's not.
> whereas in Rust, similar behavior seemed to depend on the object type.
It's best to think of that as an exception to the rule created specifically for numbers and other similar small, cheaply copied things.
If you need to move `a` but `a` has a trait Copy then you copy instead.
> Rust has its own move operator as well, despite destructive move being the default behavior for assignment.
I don't think that's true? Rust has a `move` keyword but it's a part of closure definition that makes it take all the variables from its environment by move, even if it doesn't need it. Unless you are talking about something else...