Manual Memory

It gets worse

use std::rc::Rc;
use std::cell::RefCell;

type Link<T> = Rc<RefCell<Node<T>>>;

struct Node<T> {
  data: T,
  next: Option<Link<T>>,
  previous: Option<Link<T>>,
}

fn main() {}
  • Rc is reference counting pointer 1
  • copying Rc increments counter
  • when Rc handle goes out of scope it decrements counter
  • RefCell is a type that allows interior mutability 1

Too Many Linked Lists 1