October 2018
Beginner
180 pages
4h 48m
English
If the self value is moved into the function, it's just like moving any other value; we can't continue to use it where it used to be anymore. Here is a function:
impl Point2D { pub fn transpose(self) -> Point2D { return Point2D {x: self.y, y: self.x}; }}
This can be said to consume the self value. The value is moved into the function's scope when it is called, and the old variable that used to contain the value is no longer usable. This particular function returns a new, different Point2D value, so the value of self is completely gone once this function is done running.
There are reasons why this might be exactly the behavior we want. In the previous example, the function transforms the self value into something new, which is ...
Read now
Unlock full access