pub fn push(&mut self, elem: i32) {
let new_node = Box::new(Node {
elem: elem,
next: self.head,// 错误:不能移动借用的内容
});
self.head = Link::More(new_node);
}
用**mem::replace()
**函数可以窃取借用的值,将其替换成另一个值。
pub fn replace<T>(dest: &mut T, src: T) -> T
use std::mem;
pub fn push(&mut self, elem: i32) {
let new_node = Box::new(Node {
elem: elem,
next: mem::replace(&mut self.head, Link::Empty),
});
self.head = Link::More(new_node);
}