Borrow checker Advanced
26 Moving out
You can't move a value out from behind a reference -- that would leave a hole. The fix is to swap something valid into its place and hand back the old value. std gives you take for exactly this.
Fix Slot::take: take the item out of &mut self, leaving None behind.
Hints
Option::takedoes exactly this:self.item.take().
Reveal solution
struct Slot { item: Option<String> }
impl Slot {
fn take(&mut self) -> Option<String> {
self.item.take()
}
}