๐Ÿ‘‰ Rust Pointers

Types

References

Rule: Single writer or multiple readers

  • Borrowing: &..., e.g. &i32
    • โ†’ โ€œborrowsโ€ a reference to the variable
    • & mut ...: exclusive reference
      • no other references possible while the exclusive one exists
  • Dereference: *..., e.g. *variable
    • โ†’ access the value of variable

Boxes

Simple way to allocate a value to the heap

  • Allocation: Box::new(...), e.g. Box::new(x)

Unsafe pointers

Can be used in unsafe block