trpl-zh-cn/listings/ch15-smart-pointers/listing-15-25/src/main.rs

21 lines
329 B
Rust
Raw Normal View History

2022-02-06 16:43:51 +08:00
use crate::List::{Cons, Nil};
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Debug)]
enum List {
Cons(i32, RefCell<Rc<List>>),
Nil,
}
impl List {
fn tail(&self) -> Option<&RefCell<Rc<List>>> {
match self {
Cons(_, item) => Some(item),
Nil => None,
}
}
}
fn main() {}