鍍金池/ 問答/網(wǎng)絡(luò)安全/ 為何對enum 解引用會引發(fā)move?

為何對enum 解引用會引發(fā)move?

出錯的代碼:

#[derive(Debug)]
pub enum Direction {
    Up = 1,
    Down = -1,
    Left = 2,
    Right = -2,
} 
impl Direction {
    fn is_opposite(&self, another: &Self) -> bool {
        (*self as isize) + (*another as isize) == 0
    }
}

錯誤信息:
圖片描述
但是這樣的代碼是沒問題的:

match *self {
    // ...
}

我不太清楚這兩者間的區(qū)別,為什么前者會引起move 或者copy?

回答
編輯回答
伴謊
2018年9月9日 23:30