struct_RefCell
struct_RefCell (런타임 가변성 셀 구조체)
런타임에 빌림 규칙을 검사하는 가변성(mutability) 셀 타입이에요.
출처: Rust 공식 문서
본문
RefCell<T>는 컴파일 타임 대신 런타임에 빌림 규칙을 시행하는 셀 타입이에요. &self를 받는 메서드로도 내부 값을 변경할 수 있게 해 주는 인테리어 뮤터빌리티(interior mutability)를 제공해요. 빌림 규칙을 위반하면 런타임에 패닉해요.
pub struct RefCell<T>
where
T: ?Sized,
{ /* private fields */ }
예시
use std::cell::RefCell;
let c = RefCell::new(5);
*c.borrow_mut() = 7;
assert_eq!(*c.borrow(), 7);