Take member ownership of borrowed struct

51 views Asked by At

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.

0

There are 0 answers