Rc
Rc๋ ์ฐธ์กฐ ์นด์ดํ
๊ณต์ ํฌ์ธํธ์
๋๋ค.
์ฌ๋ฌ ์์น์ ๋์ผํ ๋ฐ์ดํฐ๋ฅผ ์ฐธ์กฐํด์ผํ ๊ฒฝ์ฐ ์ฌ์ฉํฉ๋๋ค:
Rcis a reference-counted shared pointer. Use this when you need to refer to the same data from multiple places:
use std::rc::Rc; fn main() { let mut a = Rc::new(10); let mut b = a.clone(); println!("a: {a}"); println!("b: {b}"); }
Rc๋ด๋ถ์ ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํด์ผ ํ๋ ๊ฒฝ์ฐ, ๋ฐ์ดํฐ๋ฅผ Cell ๋๋ RefCell๋ก ๋ํํด์ผํฉ๋๋ค.
๋ฉํฐ์ค๋ ๋์ธ ๊ฒฝ์ฐ Arc ์ฐธ์กฐ
If you need to mutate the data inside an
Rc, you will need to wrap the data in a type such asCellorRefCell. SeeArcif you are in a multi-threaded context.