Stream: t-compiler/help

Topic: Unable to borrow mutable ref immutablty

Paul Faria (Oct 14 2019 at 04:35, on Zulip):

So I'm having trouble understanding why the fn on the &'a mut impl fails to compile, while the one on the &'a impl is fine:

Is there something going on with auto-(de)ref that I'm not realizing here?

ecstatic-morse (Oct 14 2019 at 04:51, on Zulip):

I believe this occurs because &T is Copy, but &mut T is not

ecstatic-morse (Oct 14 2019 at 04:53, on Zulip):

Really what you end up with is a reborrow in the impl for &mut str (&*self.val), which makes it clearer why this error says what it says.

Paul Faria (Oct 14 2019 at 13:06, on Zulip):

Ok. I had considered reborrowing but forgotten about the Copy behavior. That makes so much more sense. Thank you!

Last update: Jan 23 2020 at 20:05UTC