我对 rust 迹斑斑还不太熟悉,我正试图把自己的头脑集中在所有权/借款的概念上.现在,我已经将代码简化为这个最小的代码示例,它会导致编译错误.
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.
我仍然保持着everything is copied by value的心态,做self.color
是完全合法的,因为那样我就可以得到Color
的副本.显然,我错了.我发现了一些关于同样错误的其他问题,但没有解决我的问题.
据我所知,这片土地归Display
人所有.因为我只借了一本书
我该怎么解决呢?