I am new to Rust and trying to bow my head to the concept of ownership / borrowing. Now I have reduced my code to this minimal code sample that gives a compilation error.
pub struct Display { color: Color, } pub enum Color { Blue = 0x1, Red = 0x4, } impl Display { fn get_color_value(&self) -> u16 { self.color as u16 } }
src/display.rs:12:9: 12:13 error: cannot move out of borrowed content src/display.rs:12 self.color as u16 ^~~~ error: aborting due to previous error Could not compile.
I'm still copied in everything by the value of mindset, where it is completely legal to do self.color , as this will give me a copy of Color . Apparently I'm wrong. I found several other questions about the same error in SO, but could not solve the problem.
As I understand it, the field belongs to someone who owns Display . Since I just borrowed a link to Display , I don't own it. Extracting Color trying to transfer ownership of Color to me, which is not possible since I do not own Display . Is it correct?
How to solve it?
rust borrow-checker
Virtlink
source share