Tour of Rust 목차

스마트 포인터 조합하기

smart pointer는 한계가 있는 것처럼 보이지만, 조합해서 사용하면 매우 강력해질 수 있습니다.

Rc<Vec<Foo>> - heap에 있는 immutable한 데이터 구조의 동일한 vector를 대여할 수 있는 복수의 smart pointer를 복제할 수 있게 해줍니다.

Rc<RefCell<Foo>> - 복수의 smart pointer가 동일한 Foo struct를 mutable/immutable하게 대여할 수 있게 해줍니다.

Arc<Mutex<Foo>> - 복수의 smart pointer가 임시의 mutable/immutable한 대여를 CPU 쓰레드 독점 방식으로 잠글 수 있게 해줍니다.

메모리 상세: