In this post, we will see how to resolve Cannot borrow *self
. How to make the fn work without string cloning?
Question:
And yes, I really need the
&mut self
here.Best Answer:
You can wrap your strings inRc
that way you can cheaply clone
the Rc
and have something owned so you don’t reference the original struct:Rc::get_mut
or wrap further in RefCell
or similar.Solution to the original underspecified question:
The most straight forward solution is to just remove the
String
from Foo
for the baz
call:If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com
Leave a Review