[Media] Move self

50 points SuccessfulAd2010
[Media] Move self

Move self

Dear Rustaceans,

I’m pretty sure you can help me out.

This is the max method on Rectangle:

fn max(self, other: Rectangle) -> Rectangle {

Rectangle {
width: self.width.max(other.width),
height: self.height.max(other.height),
}

}

I want to confirm my understanding here.

As I understand in the posted image. &mut self path actually has RO(*W), which means its totally legal to call the max() method within the set_to_max method. But due to Rust’s borrow checker.
The line self.max(…), takes ownership of the current instance which was passed to set_to_width. The instance is then dropped within max() on Rectangle on behalf of self. This means the instance doesn’t exist anymore. But we are still trying to access the instance again through *self in set_to_width, which is already dropped in max().
So that’s why the program won’t compile.
I’m I getting this right?
Please correct me if I’m wrong.
Thank you.