On this page
  1. RefCell
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

RefCell

Prev: `Rc` | Up: smart_pointers | Next: `Cow`
Rel: smart_pointers, rust/builtins
Ref: Rust std — RefCell
Tags: #public #prog #rust #stdlib #smart_pointers #tier/standard


Signature & Overview

RefCell<T>

Single-threaded interior mutability enforcing borrow rules at runtime (.borrow() / .borrow_mut()).

Notes & Pitfalls

Example

use std::cell::RefCell;

fn main() {
    let log = RefCell::new(Vec::new());
    log.borrow_mut().push("started");
    assert_eq!(log.borrow().as_slice(), &["started"]);
}

Linked from

Related notes