跳至主要內容
Rust随笔(六)

Rust随笔(六)

我们在随笔五中提到过RcRefCell的概念,这两个工具给复杂的变量引用场景给予了强大的支持,这里有个问题,我们首先看看下面这一段代码:

use std::rc::Rc;
use std::thread;

fn main() {
    let data = Rc::new(5);
    let data_clone = Rc::clone(&data);
    
    thread::spawn(move || {
        println!("Data from new thread: {}", data_clone);
    });
}

Mr.Lexon大约 9 分钟rustrustRcArc
rust随笔(五)

Rust随笔(五)

本篇讨论两个东西:

  1. RcRefCell
  2. Reference (&) (在这里我们用引用代替Reference) 在前面的随笔中,提到了“引用”的概念,我们回顾一下这个基础函数:
fn judge_size<'a>(x:&'a str,y:&'a str) -> &'a str {
	if (x > y){
		x
	}else{
		y
	}
}

Mr.Lexon大约 12 分钟rustrustRc