1

I have the following function:

pub fn finish_frame(&mut self) {
    if self.frame.is_none() {
        return;
    }

    self.frame.unwrap().finish().unwrap();
}

When I compile, the compiler gives me the following error:

error[E0507]: cannot move out of borrowed content
  --> src/engine/renderer.rs:65:9
   |
65 |         self.frame.unwrap().finish().unwrap();
   |         ^^^^ cannot move out of borrowed content

self.frame is a Option type, finish(mut self) takes ownership of self. Since finish(mut self) is a library function, I cannot change that.

Any idea on how I could do this? Ideally without implementing a copy trait, which feels like a waste of memory and CPU time.

I am a Rust newbie, so please forgive me if this is a stupid mistake.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Martin Fink
  • 1,746
  • 3
  • 16
  • 32
  • 1
    Duplicate of http://stackoverflow.com/q/33705664/155423; http://stackoverflow.com/q/27098694/155423; http://stackoverflow.com/q/33204273/155423; or http://stackoverflow.com/q/38776577/155423, take your pick. – Shepmaster Dec 28 '16 at 22:15
  • 1
    @Shepmaster the second one helped me! Thanks! – Martin Fink Dec 28 '16 at 22:20
  • 2
    Great! I just added another answer to that one with a special case that is likely to be helpful to your exact situation. – Shepmaster Dec 28 '16 at 22:23

0 Answers0