Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Test MDX File V12

Rust Memory Lab

Drag a Rust type onto the stack. Owned types — Box, String, Vec — also claim space on the heap.

Stackbase = 0x7FFFFFE0
32 / 32 bytes used0 free
+0
+8
+10
+18
a
0x00603000
b
ptr
0x00603004
len
0x05
cap
0x05
byte 0
8
16
24
Heapbase = 0x00603000
9 / 32 bytes used23 free
+0
+8
+10
+18
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
*a
42
*b
"hello"
byte 0
8
16
24

Type Palette — drag onto the stack

bool1B
i81B
char4B
i324B
f324B
i648B
f648B
Box<i32>8B + heap
String24B + heap
Vec<i32>24B + heap
integer types
floating point
character
boolean
owned (heap-backed)

Declared bindings

TypeNameValueStack addrStackHeap
Box<i32>a420x7FFFFFE08 B4 B
Stringbhello0x7FFFFFE824 B5 B
Try this:Click Worked example. Notice that a: Box<i32> stores an 8-byte pointer on the stack and just 4 bytes on the heap — the value lives over there. b: String is the heaviest: 24 bytes of stack record (pointer + length + capacity) plus the actual UTF-8 bytes on the heap. Together they fill the 32-byte stack exactly. Now clear all and drag an i32 in — it claims 4 stack bytes and zero heap. Then drag a char — it claims 4 bytes too, not 1. Rust's char is a Unicode scalar value, not a byte.

Rust Mutability Lab

Toggle mut on the binding and on the reference. To mutate through r, you need both.

Sourcequadrant: `x` (immutable) + no reference
let x: i32 = 5;
Stackone binding · optional reference
base = 0x7FFFFFD8
x
i32
5
4B·FFD8

Configure the source

x type
x mut?
r
r borrow

Run a statement

Try this:Set x mut? to let x, declare r, and set its borrow to &mut x. Notice the red banner — Rust refuses, because you can't hand out a mutable reference to an immutable binding. Now flip x mut? to let mut x and the configuration compiles. Press *r = … and watch the value update through the reference. Finally, switch x type to String — the rules are identical, but the action becomes r.push_str(", world") and the heap data updates instead.

Rust Thread Lab

What can cross the thread boundary? Three walls — 'static, Send, and Mutex — and how to cross each.

Phase:pre-spawnspawnedjoined
Stack — mainbase = 0x7FFFFFD8
Frame is empty. Declare a binding to begin.
Heap — shared between threadsbase ≈ 0x00603000
Heap is empty. Vec, Rc, Arc, and Mutex all allocate here.

1 · Declare in main

3 · Spawn the thread

Try this:Declare v, leave its capture mode at &, and press the plain spawn. Rust refuses — the closure might outlive main. Switch to spawn move and it compiles. Now reset and try the same with rc — even with move, Rust refuses because Rc isn't Send. Swap to arc and it works. Finally, declare shared, capture it as .clone(), spawn-move, and increment through the lock — both threads now share write access, mediated by the Mutex.