memtrace
PlaygroundBetaLearn memoryFollow on

Getting started

  • Introduction

Unsafe Rust

  • Introduction
  • Raw pointers
  • Undefined behavior

Real world

  • Cloudflare: 100 TB saved in 1.1.1.1's DNS cache

Playground

  • How the Playground works
  • What the Playground can't do yet

Unsafe Rust

Unsafe Rust

What unsafe unlocks, what it promises, and how it goes wrong

What unsafe means

An unsafe block doesn't turn the borrow checker off. Everything inside it is still checked the normal way; it only unlocks five extra abilities the compiler can't verify on its own

  • Dereference a raw pointer, *const T or *mut T
  • Call an unsafe function or method, including functions from C
  • Read or write a static mut
  • Implement an unsafe trait such as Send or Sync
  • Read the fields of a union

The deal

Writing unsafe is a promise: I've checked the rules the compiler can't. If the promise is wrong, the result is undefined behavior, not a compile error

Resources

  • The Rust Book: Unsafe RustThe five unsafe abilities, with examples
  • The RustonomiconThe guide to writing unsafe Rust correctly
PreviousLearn memoryNextRaw pointers

On this page

  1. What unsafe means
  2. Resources