Back to course

Smart Pointers: Box<T>

Rust for Systems & Web3 Security

Heap Allocation

Box<T> allows you to store data on the heap rather than the stack. This is useful for:

  1. Types whose size can't be known at compile time.
  2. Transferring ownership of a large amount of data without copying it.

rust let b = Box::new(5); println!("b = {}", b);