Reputation:
pub struct Themepark {
attraction: Box<Attraction>
}
Note: Attraction
is a trait!
impl Themepark {
pub fn open(&mut self) -> Result<(), ()> {
let attraction = Box::into_raw(self.attraction);
...
}
}
that gives me
> cannot move out of borrowed content
for self.attraction
inside Box::into_raw
Now I do understand what that particular error-message means, but I don't understand how to solve it as Box::into_raw
expects a Box<T>
as argument, not a reference or anything.
https://doc.rust-lang.org/std/boxed/struct.Box.html#method.into_raw
Upvotes: 1
Views: 569
Reputation: 22273
You won't be able to use that function on self.attraction
while mutably borrowing self
; as per the very first line in its docs:
Consumes the
Box
You either need to .clone()
it or use a function that consumes self
(e.g. fn open(self)
).
I recommend re-reading The Rust Book's chapter on Ownership.
Upvotes: 2