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