1. pub fn push(&mut self, elem: i32) {
    2. let new_node = Box::new(Node {
    3. elem: elem,
    4. next: self.head,// 错误:不能移动借用的内容
    5. });
    6. self.head = Link::More(new_node);
    7. }

    用**mem::replace()**函数可以窃取借用的值,将其替换成另一个值。

    1. pub fn replace<T>(dest: &mut T, src: T) -> T
    1. use std::mem;
    2. pub fn push(&mut self, elem: i32) {
    3. let new_node = Box::new(Node {
    4. elem: elem,
    5. next: mem::replace(&mut self.head, Link::Empty),
    6. });
    7. self.head = Link::More(new_node);
    8. }