2
我目前正在學習Rust並編寫簡單的遊戲。但是有一個錯誤。有字符(S)(ENUM)的向量,並試圖(在載體的一些索引值),則編譯器返回值時顯示低於無法移出解引用(由於索引導致隱含解引用)
rustc main.rs
field.rs:29:9: 29:39 error: cannot move out of dereference
(dereference is implicit, due to indexing)
field.rs:29 self.clone().field[index - 1u] as int
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
main.rs錯誤:
mod field;
fn main() {
let mut field = field::Field::new(3u);
field.change_cell(1, field::Character::X);
println!("{}", field.get_cell(1));
}
field.rs:
pub enum Character {
NONE, X, O,
}
pub struct Field {
field: Vec<Character>,
size: uint,
cells: uint,
}
impl Field {
pub fn new(new_size: uint) -> Field {
Field {
field: Vec::with_capacity(new_size*new_size),
size: new_size,
cells: new_size*new_size,
}
}
pub fn change_cell(&mut self, cell_number: uint, new_value: Character) -> bool {
...
}
pub fn get_cell(&self, index: uint) -> int {
self.field[index - 1u] as int
}
}
歡迎來到堆棧溢出!將來,您應該嘗試創建[最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)。這有助於我們更快地回答您的問題,並可能幫助您自己解決問題! – Shepmaster