pub fn pop(&mut self) -> Option<i32> {
let result;
match &self.head {
Link::Empty => {
result = None;
}
Link::More(ref node) => {
result = Some(node.elem);
self.head = node.next;// 不能移动借用的内容: node.next
}
};
result
}
pub fn pop(&mut self) -> Option<i32>{
// mem::replace() 会返回替代前的值(所有权类型)
match mem::replace(&mut self.head,Link::Empty){
Link::Empty => None,
Link::More(node) => {// 这里node是拥有所有权的Link,也可以这样写: ref mut node
self.head = node.next;// 然后这里这样写: mem::swap(&mut self.head,&mut node.next);
Some(node.elem)
}
}
}