3 ms·
Being read only and move semantics are orthogonal, you can read and write with or without moving. So you shouldn't make assumptions whether something will be m
by eddd-ddde 3y ago
Being read only and move semantics are orthogonal, you can read and write with or without moving.
So you shouldn't make assumptions whether something will be moved or not based on read only preconditions.
- fauigerzigerk 3y agoMoving out of a variable changes it's state. That's not read-only.
- eddd-ddde 3y agoThere is a difference between a variable and a value. The value is definitely read only or you would need a mut modifier. The variable binding changes in a similar way to shadowing it with a new 'let' on the same name.
- fauigerzigerk 3y agoThis would imply that the variable can get its value back once the new binding is out of scope. But that is not the case as this doesn't compile: let s1 = String::from("abc"); { let s2 = s1; } println!("{}", s1); //borrow of moved value: `s1` But I do understand what you're getting at. In a sense, a move is not a runtime concept at all. The compiler simply considers the variable as no longer readable unless and until a new value is actually written to it.