我正在使用此处的示例。
#[derive(Debug)]
enum List {
Cons(i32, RefCell<Rc<List>>),
Nil,
}
impl List {
fn tail(&self) -> Option<&RefCell<Rc<List>>> {
match *self {
Cons(_, ref item) => Some(item),
Nil => None,
}
}
}
给定函数签名为
&self
,self
是指向List
的引用类型,*self
是List
实例本身。但是我记得
match
也会拥有它匹配的对象,那么这不会对结构体造成问题吗?因为List
实例被移动到match
而没有返回。此外,
&self
不是不可变的吗?为什么我们能将self
移动到match
中呢?