Update Ch15

This commit is contained in:
Unisko PENG
2023-05-10 16:53:09 +08:00
parent f79efeab7b
commit c9c063a1e2
3 changed files with 27 additions and 19 deletions

View File

@@ -0,0 +1,8 @@
[package]
name = "rc_demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -0,0 +1,17 @@
use std::rc::Rc;
#[derive(Debug)]
enum List {
Cons(i32, Rc<List>),
Nil,
}
use crate::List::{Cons, Nil};
fn main() {
let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
let b = Cons(3, Rc::clone(&a));
let c = Cons(4, Rc::clone(&a));
println! ("b 为: {:?}\nc 为: {:?}", b, c);
}