Rc

Rc๋Š” ์ฐธ์กฐ ์นด์šดํŒ… ๊ณต์œ  ํฌ์ธํŠธ์ž…๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ์œ„์น˜์˜ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐธ์กฐํ•ด์•ผํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

Rc is 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 as Cell or RefCell. See Arc if you are in a multi-threaded context.