Companion reference

Aquascope decoder for the opening diagram

Keep the opening diagram visible while reading this page. Aquascope is a separate teaching tool, not Rust syntax. It can draw both what Rust checks before code starts and what the program's data looks like while the code runs.

The opening diagram draws only the running-data half. It shows four memory pictures and contains no permission letters. “R, W, O permission marks” is therefore forward material for a later book page, and it is the one section on this page you cannot match against the opening diagram.

Read this page in order. “Words used by the decoder” explains the vocabulary that every later section relies on. When an example needs new syntax, that same entry explains it immediately. No knowledge of Rust, computer memory, or systems programming is assumed.

Words used by the decoder

From source text to a running program

Source code
Text written by a programmer in a programming language. Rust source files normally end in .rs.

Example: fn main() {} is complete minimal Rust source: fn starts a function definition, main is its name, () says it has no inputs, and {} encloses its empty body.

TypeScript relationship: a .ts file is TypeScript source code.

Executable program
File that a computer can start and run. This page sometimes shortens “executable program” to “program.”

Example: main.rs is source text; a separate file produced from it is executable program.

TypeScript relationship: TypeScript is normally turned into JavaScript and run by Node.js or a browser; Rust normally produces an executable file ahead of time.

Compiler
Tool that reads and translates source code. For this binary sample, Rust's compiler either reports why the source is rejected or produces executable file that computer can start. Rust's compiler is named rustc.

Example: source text containing ??? where Rust expects code is rejected; compiler reports error instead of producing executable.

TypeScript relationship: tsc also checks source, but TypeScript errors do not inherently stop JavaScript emission: noEmitOnError must be enabled to make errors block emitted files. Rust and TypeScript also check different sets of rules.

Compile time
Period when the compiler is reading and checking source code, before the executable starts.

Example: compiler reporting unknown variable name is compile-time event.

TypeScript relationship: TypeScript type errors also come from compiler, but emitted JavaScript can still run when project configuration permits emission.

Runtime
Period after an executable has started and its instructions are running.

Example: for minimal source fn main() {}, entering empty function body and returning from it are runtime events.

TypeScript relationship: JavaScript executing inside Node.js or a browser is runtime behavior.

Parts of code

Keyword
Word reserved by a language for a particular purpose. A reserved word cannot be reused freely as a variable name.

Example: fn, let, and mut are Rust keywords.

TypeScript relationship: function, let, and class are TypeScript keywords.

Function and function call
Function is named section of code. Code inside function runs when function is called. A call is written with a function name followed by parentheses.

Example: greet(); calls a function named greet.

TypeScript relationship: TypeScript functions and calls have the same broad role.

main and automatic startup
main is entry point into this executable's Rust code. Operating-system and Rust-provided startup work happens first; Rust's runtime then calls main automatically. Programmer does not add main(); at end of Rust file.

Example: starting an executable built from fn main() { let count = 5; } performs startup setup, enters main's body, then runs let count = 5;.

TypeScript relationship: the name main has no special behavior in TypeScript. A TypeScript function named main runs only if other code calls main().

Parameter and argument
Parameter is input name written in function definition. Argument is value supplied by particular function call.

Example: in complete definition fn show(number: i32) {}, number is parameter and i32 means whole-number type; in show(5), value 5 is argument.

TypeScript relationship: TypeScript uses the same parameter and argument distinction.

Function body
Code enclosed by function's braces, { and }.

Example: in fn greet() { let word = 5; }, let word = 5; is the body.

TypeScript relationship: TypeScript also uses braces around a normal function body.

Block and scope
Block is code between matching braces. Scope is region of source where a name is usable. In simple let declaration used here, local variable's name is visible from its declaration to end of enclosing block.

Example: in fn demo() { let count = 5; }, count's scope ends at that closing brace, and no later code can name count.

TypeScript relationship: TypeScript let is also block-scoped, so this name-visibility rule matches. A later entry separately explains when Rust destroys values.

Value
Actual piece of data handled by code.

Example: 5 is a number value, and true is a yes-or-no value.

TypeScript relationship: values have the same broad meaning in TypeScript.

Expression
Piece of code that produces a value.

Example: 2 + 3 is expression producing value 5.

TypeScript relationship: 2 + 3 is also TypeScript expression.

Statement and semicolon
Statement is component of block that declares name or evaluates expression for its effect. After ordinary expression, ; makes it an expression statement and discards expression's result. let declaration also ends with semicolon.

Example: let score = 5; is declaration statement: let declares name score with initial value 5; 2 + 3; computes 5 and then discards it.

TypeScript relationship: TypeScript also has statements, but its expression and return rules differ.

Type and field
Type names a category of values and the operations allowed on them. Field is named part stored inside a value of a type with multiple parts.

Example: i32 is a type; a type describing a point could store fields named x and y, so one point value would hold two numbers under those two names.

TypeScript relationship: TypeScript also checks types and object properties. Type annotations and type-only declarations are erased before JavaScript runs; Rust types also constrain runtime representation and operations.

Variable, variable declaration, and binding
Variable is programmer-chosen name for value while relevant code runs. Variable declaration creates that name. Rust documentation calls connection between name and current value a binding. After this definition, decoder may use “binding” for that connection.

Example: let score = 5; declares variable score and binds name score to value 5.

TypeScript relationship: this is closest to a TypeScript variable declaration; TypeScript programmers do not normally need “binding” as a separate term here.

Local variable
Variable declared inside one function body.

Example: in fn demo() { let count = 5; let total = 6; }, count and total are local variables of demo.

TypeScript relationship: a variable declared inside a TypeScript function is also local to that function body.

Initialization and assignment
Initialization supplies variable's first value as part of declaration. Assignment later replaces value at already initialized variable. Both spellings contain =, but they are different operations.

Example: in let mut score = 5; score = 6;, first = initializes score to 5; second assigns 6 and replaces previous value 5. Rust drops replaced value first, but dropping plain i32 performs no visible cleanup.

TypeScript relationship: TypeScript makes same declaration-versus-later-assignment distinction.

Mutation and mut
Mutation means operation alters existing data or assigns replacement value. For local value in this sample, mut on declaration permits later assignment and mutable borrowing through that binding. mut describes allowed access through binding; it is not permanent property carried by moved value.

Example: let mut score = 5; score = 6; replaces 5 with 6 through score. By contrast, let reference = &mut score; needs no mut on name reference to write *reference = 7;. Here &mut creates mutable reference and prefix * reaches value through it.

TypeScript relationship: TypeScript let permits later assignment without an extra keyword. Rust's mut has no direct TypeScript keyword equivalent.

Literal
Source-code spelling that directly represents a value.

Example: "Hello world" is a string literal; quotation marks mark its boundaries.

TypeScript relationship: "Hello world" is also a TypeScript string literal.

Text and computer memory

Memory
Space inside computer used to hold program data while program runs.

Example: while a program runs, it needs runtime memory for current values and other program data. Source and executable files occupy storage too, but they are not runtime memory pictures Aquascope draws.

TypeScript relationship: TypeScript programs also use memory, but JavaScript normally hides its layout.

ASCII
Text encoding with 128 numbered codes, from 0 through 127. Codes include control signals plus printable unaccented English letters, digits, space, and punctuation. Text using only these codes is called ASCII-only.

Example: ASCII assigns number 72 to H and number 32 to the space character.

TypeScript relationship: "H".charCodeAt(0) evaluates to 72, because JavaScript's character numbers agree with ASCII over that range.

Bit and byte
Bit is binary digit, either 0 or 1. In Rust, byte is storage unit of eight bits. Eight bits can encode 256 patterns; Rust type u8 interprets them as whole numbers from 0 through 255.

Example: byte holding ASCII H has numeric value 72.

TypeScript relationship: one element of a TypeScript Uint8Array holds one byte.

UTF-8
Unicode assigns numbers to text symbols from many writing systems. UTF-8 represents each Unicode scalar value with one to four bytes. It uses same one-byte representation as ASCII for every ASCII code.

Example: ASCII-only text Hello uses five UTF-8 bytes; literal scalar value é, Unicode U+00E9, uses two UTF-8 bytes.

TypeScript relationship: JavaScript's string model uses UTF-16 code units; encoding text as UTF-8 bytes normally requires an API such as TextEncoder.

String
Rust type for UTF-8 text whose contents can grow or shrink after creation. The type tracks where its bytes are, how many bytes are text, and how much room is reserved.

Example: String::from("Hi") creates a String containing two UTF-8 bytes.

TypeScript relationship: TypeScript string values cannot be modified internally; an expression such as text += "!" produces a different string value. Rust String has no exact TypeScript string mirror.

Method
Function attached to type and called with dot syntax on value of that type.

Example: let s = String::from("Hi"); let n = s.len(); creates s, calls len, and binds byte count 2 to n without changing s.

TypeScript relationship: TypeScript object and class methods use similar dot-call syntax.

Allocation, deallocation, and buffer
Allocation is block of memory reserved for a value. Deallocation returns that block to allocator so it can be reused. Buffer is allocated block reserved to hold a sequence of items such as bytes.

Example: in this Aquascope model, String::from("Hi") would obtain buffer for two text bytes; returning that buffer to allocator later is deallocation.

TypeScript relationship: JavaScript normally deallocates objects automatically through garbage collection, meaning the runtime later reclaims objects that code can no longer reach through any variable.

Stack and frame
Aquascope uses Stack for active function calls. Each call gets frame that lists its local variables. This is learning model; compiler may represent local values differently without changing Rust rule being taught.

Example: while fn demo() { let count = 5; } runs, demo's frame lists one local variable, count.

TypeScript relationship: JavaScript engines also track active function calls, but TypeScript does not expose their memory layout.

Heap
Memory area used for dynamically allocated buffers and other values.

Example: even though compiler already knows literal "Hello world"'s byte count, String::from creates owned growable buffer on heap when statement runs.

TypeScript relationship: JavaScript objects use heap memory, but TypeScript does not expose their addresses or cleanup timing.

Pointer and pointee
Pointer is value that identifies another location in memory. Pointee is data at the location identified by the pointer. Aquascope draws pointer as dot.

Example: a String's stack value holds pointer, and its heap text bytes are that pointer's pointee.

TypeScript relationship: JavaScript engines use hidden references for objects, but ordinary TypeScript has no explicit memory-address pointer.

Length, capacity, and metadata
For String, length is number of bytes currently used. Capacity is number of bytes current buffer can hold before String must obtain more capacity. Obtaining more capacity may grow allocation in place or replace it; this Aquascope run replaces it. Metadata means small values that describe other data; pointer, length, and capacity describe String's bytes.

Example: String::from("Hi") has length 2; if its allocation had room for four bytes, its capacity would be 4 and two positions would be reserved but unused.

TypeScript relationship: arrays expose length, but TypeScript does not expose JavaScript array capacity.

Rust access and cleanup rules

Ownership and owner
Ownership is responsibility to destroy value and release resources that value owns. This sample has one String that is sole owner of one heap buffer. This is sample-specific model, not claim that every Rust allocation always has exactly one owner.

Example: String value created by String::from("Hi") owns its heap buffer; destroying that String deallocates buffer.

TypeScript relationship: ordinary TypeScript runtime does not enforce Rust's deterministic owner-and-drop rules; garbage collection has no direct ownership equivalent.

Scope end and automatic cleanup
When normal control leaves block, Rust drops each initialized local value still associated with that block. Value already moved or explicitly dropped is no longer initialized there and is not dropped again. Explicit drop is an option for ending value earlier, not requirement for cleanup.

Example: in fn demo() { let text = String::from("Hi"); }, text's heap buffer is deallocated at the closing brace, and the source contains no cleanup instruction at all.

TypeScript relationship: leaving a TypeScript function does not free its objects at that moment. Garbage collection reclaims them at an unspecified later time, so the exact cleanup point Rust guarantees has no TypeScript equivalent.

Copy, Clone, and non-copy values
Trait is named capability a type can implement. Copy trait permits implicit bit-for-bit duplication, so assignment or argument passing leaves source usable. Whole-number types such as i32 and u8 are Copy. Bitwise-copying String would duplicate pointer and cleanup responsibility, risking deallocation of same buffer twice, so String is not Copy. Its explicit clone() instead allocates and copies text safely. Every move rule below applies to non-Copy types only.

Example: after let a = 5; let b = a; both a and b are usable; after let a = String::from("Hi"); let b = a; only b is usable; after let b = a.clone();, both strings are usable and own separate buffers.

TypeScript relationship: TypeScript assignment copies primitive value or object reference, and source variable remains usable in both cases. It has no equivalent of move invalidating source variable.

Move
Move transfers value of a non-Copy type, and its ownership, from one variable or function input to another. Old variable is not “empty”; compiler rejects later reads through it.

Example: after let first = String::from("Hi"); let second = first;, second can be used but compiler rejects later use of first. The same two lines written with 5 in place of the String leave both names usable, because i32 is Copy.

Reading first afterward produces error[E0382]: borrow of moved value: `first`, and that message states the reason itself: “move occurs because first has type String, which does not implement the Copy trait.”

TypeScript relationship: there is no direct TypeScript move. Assigning object to another TypeScript variable leaves both variables usable and pointing to same object.

Reference
Reference is compiler-checked pointer value that accesses data owned elsewhere. Reference does not become responsible for destroying that data.

Example: after let part = &text[0..2];, part contains reference to first two bytes and text still owns them.

TypeScript relationship: TypeScript has no compiler-checked reference type with Rust's access rules.

Borrow
Borrow is temporary access created when code uses &, as in &text[0..2]. Compiler limits what owner can do while resulting reference will still be used.

Example: in let text = String::from("Hello"); let part = &text[0..2];, part borrows first two bytes from text without copying them.

TypeScript relationship: TypeScript has no borrow operator and no compile-time rule that temporarily blocks original variable this way.

Slice, str, and &str
Slice is view into contiguous sequence whose length is known at runtime rather than fixed in type. Rust calls such type dynamically sized. Contiguous means included positions sit next to each other with no gaps. str is dynamically sized string-slice type containing valid UTF-8 bytes; code normally accesses it through pointer type such as &str. Shared reference &str carries pointer and byte length without owning or copying referred bytes.

Example: &text[0..2] for a String holding Hello has type &str, starts at H, and has length 2.

TypeScript relationship: string.slice returns a new string value, not compiler-checked borrowed view, so it is not direct mirror.

drop
Rust function that receives value, ends that value immediately, and performs its cleanup. It is a way to end a value earlier than its scope would; cleanup already happens at scope end without it. Passing an owned non-Copy value to drop moves it, so the original variable becomes unusable. Passing existing Copy variable such as an i32 copies its value into drop; copied argument is dropped and original variable remains usable. rustc warns about this ineffective call.

Example: drop(text); ends a String and deallocates its heap buffer at that line instead of at the enclosing closing brace.

TypeScript relationship: delete removes object property and does not destroy object; ordinary TypeScript has no direct operation that immediately frees object's memory.

Undefined behavior, safe Rust, and unsafe
Undefined behavior is execution for which Rust provides no promise about result. Reading from deallocated memory is one example. Safe Rust operations cannot perform dangling read in this sample: compiler rejects source before executable is produced. unsafe Rust and foreign code, meaning linked code written in another language, can perform operations compiler cannot fully check; programmer must uphold their safety requirements or program can cause undefined behavior. Safe checks are deliberately cautious, so they also reject some programs that would have been safe at runtime.

Example: code that read a borrowed slice after its allocation had been deallocated would be reading bytes that no longer belong to any string, which is why the compiler refuses to build it.

TypeScript relationship: ordinary TypeScript does not expose deallocated-memory reads; it has no direct language-level equivalent of this Rust memory error.

Copyable TypeScript anchor example
function main(): void {
  let text = "Hello world";
  text += "!";
  console.log(text);
}

const first = { text: "Hello" };
const second = first;
second.text += "!";
console.log(first.text, second.text);

main(); // main has no automatic meaning in TypeScript

Running it prints Hello! Hello! and then Hello world!. The first line proves both names still reach the same object after assignment. The last line runs last because nothing calls main until the file's final statement.

This one example shows three contrasts: TypeScript calls main explicitly, let needs no mut, and both first and second remain usable after assignment.

Every piece of the code panel

fn main() {
    let mut s = String::from("Hello world");
    let hello = &s[0..5];
    s.push_str("!");
    drop(s);
}

The widget shows four of these six lines. Its copy of the source contains fn main() { and the closing }, but the book's widget hides that pair, so the panel beside you lists only the four statements while this page lists the whole function. The eye control reveals the hidden pair.

Each displayed statement carries a badge, L1 through L4, at its end. A badge is Aquascope's label rather than Rust syntax. It links one statement to the memory picture carrying the same badge, and each picture shows the state after that statement has run.

fn main() { ... }

fn
Keyword that starts Rust function definition.

Example: fn greet() {} defines function named greet.

main
Special function whose initial call is performed automatically when executable starts.

Example: launching this executable enters main; Rust source does not contain separate main(); call.

()
Empty parameter list, meaning main declares no input parameters.

Example: a function with one parameter could begin fn greet(name: String).

{ }
Braces marking start and end of function body. On normal exit, closing brace drops each initialized local value still associated with this block.

Example: all four sample statements are between main's braces.

let mut s = String::from("Hello world");

let
Keyword starting variable declaration. Declaration creates binding between variable name and value.

Example: let score = 5; binds name score to value 5.

mut
Keyword permitting mutable access through this String binding. Here it allows compiler to create temporary &mut String reference required by push_str. If this String later moves into new binding, new declaration independently decides whether mutable access through new name is permitted.

Example: s.push_str("!") changes s's text from Hello world to Hello world! and byte length from 11 to 12. It may reuse current buffer or replace full buffer with larger allocation. Without mut, compiler rejects this exact call.

s
Programmer-chosen variable name. Letter has no built-in Rust meaning.

Example: later statements use same name in s.push_str("!") and drop(s).

=
In this let declaration, equals sign introduces initializer on right. This is initialization, not later assignment to existing variable.

Example: value produced by String::from(...) becomes initial value reached through s.

String
Type of new growable UTF-8 text value.

Example: at L1, this String owns buffer holding Hello world.

:: and from
:: separates the parts of a path. Here the path names a function attached to the type itself rather than to an existing value. The same separator also names items inside modules, as in std::ptr, so read it as “look inside” rather than as a type-only marker. from is selected function's name.

Example: String::from("Hi") creates new String from literal "Hi".

"Hello world"
Literal supplying source text. Quotation marks mark boundaries and are not part of text. String::from copies literal's eleven bytes into owned buffer shown by Aquascope.

Example: heap cells at L1 show H through d, not quotation marks.

;
Semicolon ends every statement shown here. It is required after let; after standalone method or function call, it makes expression statement that keeps call's effect and discards returned value.

Example: s.push_str("!"); keeps text mutation and discards call's () result.

let hello = &s[0..5];

hello
New local variable whose type is inferred as &str.

Example: expanded L2 view shows hello with pointer and length 5.

&
Borrow operator that creates reference instead of transferring ownership.

Example: hello can read five bytes, but s's String still owns their buffer.

[ ]
Indexing brackets selecting part of value.

Example: brackets apply range 0..5 to s's text.

0..5
Range starting at byte position 0 and stopping before byte position 5. Both endpoints must be UTF-8 character boundaries or range indexing panics at runtime.

Example: positions 0 through 4 spell Hello, so this range is valid; 0..1 would panic for é, whose encoding occupies bytes 0 and 1.

The sample never reads hello later. Compiler therefore treats borrow as finished before next statement. Example: if let count = hello.len(); were added after push_str, borrow would still be needed there and compiler would reject earlier push_str call with error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immutable.

Read that error message carefully, because it names the real rule. The compiler refuses the combination of a live borrow and a mutating call. It does not decide by checking whether the buffer happened to move. A version of push_str that grew the buffer in place would be rejected the same way.

s.push_str("!");

.
Dot selecting method on value to left.

Example: s.len() selects method len on s.

push_str
String method that appends bytes from string slice. Its input type is &str; literal "!" has that string-slice type, so method reads literal's byte without taking ownership of literal. It adds exclamation-mark byte, increasing length from 11 to 12. Because current capacity is only 11, this Aquascope run obtains capacity-22 allocation, copies eleven existing bytes, appends new byte, and deallocates old allocation. Capacity 22 is observed here, not guaranteed growth rule.

Example: before call, s contains Hello world; after call, it contains Hello world!.

("!")
Parentheses contain argument passed to method. Argument is one-character string literal.

Example: literal supplies exclamation-mark byte visible at end of heap at L3.

drop(s);

drop
Function ending supplied value immediately and performing cleanup. This line is not what makes cleanup happen. Without it, the same buffer would be deallocated one line later, at main's closing brace. The line exists so the diagram can show that deallocation while a badge is still available to label it.

Example: at L4, heap buffer is gone because drop ended String.

(s)
Argument passed to drop. Passing owned String moves it out of s and into function; s cannot be used afterward.

Example: after drop(s);, compiler rejects later s.push_str("?"); because s's value was moved into drop.

Every control and border

L1, L2, L3, L4
Aquascope snapshot labels, not Rust syntax. Badge beside source statement matches memory picture carrying same badge.

Example: L2 beside borrow matches picture where both s and hello exist.

Copy icon
Copies the whole Rust source the widget holds, including the two lines the widget hides. Result is the six-line function, not the four displayed statements.

Example: pressing it yields text beginning fn main() { and ending }.

Eye icon
Shows or hides the helper source lines concealed by the book's widget. Here that pair is fn main() { and the closing }. This display choice does not change values in snapshots.

Example: pressing it once makes the panel show six lines instead of four.

Binocular icon
Switches compact value picture to expanded picture of Rust's internal implementation.

Example: compact s ● expands into String, Vec, RawVec, and pointer wrappers.

Dashed outer border
Boundary of one embedded Aquascope widget, with no Rust meaning.

Example: source panel and all four snapshots sit inside it.

Dashed Stack and Heap borders
Group displayed values by memory area, with no Rust syntax meaning.

Example: s sits inside Stack border and text bytes sit inside Heap border.

Solid nested borders
Show value and fields contained inside it in expanded view. Nesting means “contains,” not “points to.”

Example: String border contains field vec, whose Vec border contains buf and len.

Horizontal scrollbar
Moves across picture wider than page and has no Rust meaning.

Example: expanded picture may need horizontal scrolling to reach heap bytes.

Every label and mark in the compact runtime picture

Stack
Aquascope area showing active function frames and local variables.

Example: main's frame contains s at L1.

main
Frame for automatically started main function call.

Example: at L2, this frame lists both s and hello.

Heap
Aquascope area showing runtime-sized allocations. Screenshot says Heap, not Help.

Example: eleven byte cells for Hello world appear there at L1.

Absent Heap box
When a snapshot has no live heap allocation, Aquascope omits the Heap box instead of drawing an empty one. An absent box therefore means “nothing allocated,” not “this view is unavailable.”

Example: L4 shows only a Stack box, because drop(s) deallocated the sole heap buffer.

●
Aquascope pointer mark, not Rust syntax. A cell holding this dot holds a pointer rather than a displayed number or character.

Example: at L1, s's only visible cell holds a dot, meaning s reaches its text through a pointer.

Arrow or connector
Curved line links pointer dot to heap data it identifies. Chromium verification displays these lines; learner's Firefox view can omit them even though pointer dots and target bytes still render. Missing line is browser-rendering issue, not different Rust state.

Example: at L1, visible Chromium line connects s's dot to first heap byte H. If Firefox omits line, same dot still represents pointer to start of text.

What the compact view leaves out
The compact picture shows one dot for s and no len or cap. Those numbers exist while the program runs; the binocular view is what displays them.

Example: at L1, the compact view shows s ●, and the binocular view shows that same value with len 11 and cap 11.

⦻
Aquascope mark saying old pointer target is no longer allocated. It is not Rust syntax and is not necessarily value stored by program.

Example: at L3, hello's old target has been deallocated, so diagram shows ⦻.

Moved-out value, shown faded and striped
Diagonal stripes across faded text mean the variable's value was moved away and the variable can no longer reach it. At L4 this appears on s together with ⦻, because the moved-out String's buffer is gone as well: one mark reports the move, the other reports the deallocation.

Example: s is faded and striped at L4 because drop(s) consumed its String.

Character-like heap cells
One displayed cell per byte in this ASCII-only example. Other UTF-8 characters may require multiple cells.

Example: first five cells are H, e, l, l, o.

What changes from L1 to L4

L1: after String::from("Hello world")

Stack
main frame contains s, displayed as a single pointer dot.
Heap
Eleven bytes spell Hello world.
Exact effect
New String owns buffer containing copy of literal's bytes.

Example: the compact view shows only s ●; pressing the binocular icon reports the same value's len 11 and cap 11.

L2: after let hello = &s[0..5]

Stack
s still owns buffer; hello appears as a second dot, and the binocular view shows its length 5.
Heap
Same eleven bytes remain.
Exact effect
No text byte is copied; hello describes first five existing bytes.

Example: hello reads as Hello.

L3: after s.push_str("!")

Stack
s points to current allocation; hello now shows ⦻.
Heap
Twelve bytes spell Hello world!.
Exact effect
This Aquascope run replaced full capacity-11 allocation with capacity-22 allocation.

Example: program remains valid because it never reads hello after its creation. Rust rejects version that reads hello after push_str.

Capacity 22 is observed result of this run, not Rust language promise. Code may rely on enough capacity for current text, but not on doubling.

L4: after drop(s)

Stack
s is faded and striped with ⦻; hello also shows ⦻.
Heap
No Heap box is drawn at all, because no allocation remains.
Exact effect
drop ended owning String and deallocated buffer.

Example: compiler rejects later code that reads s, calls method on s, or passes s to another function.

What the diagram does not label

The badges stop at L4, one line before main's closing brace. A fifth program state exists there, with main's frame empty and no heap allocation, and Aquascope draws no badge for it.

That missing state carries the lesson the four badges can hide. Deleting drop(s); from this sample would not leak the buffer. It would move the deallocation from L4 to the closing brace, where Rust performs it because s's scope ends. drop chooses when cleanup happens; it is not what causes cleanup.

Every label in the binocular picture

Standard library means reusable types and functions shipped with Rust. Example: String, Vec, and drop come from Rust's standard library. Binocular picture exposes mostly private details inside that library. Their names and nesting can change with Rust version. Learn them only well enough to decode this picture.

A wrapper is value whose job is to contain another value while adding a rule. Example: NonNull wraps pointer and adds rule that pointer cannot be null. Null means special pointer value that points nowhere.

The picture's labels carry no angle brackets. The written Rust type of the vec field is Vec<u8>, and the diagram displays it as bare Vec. The same applies to every wrapper below, so do not search the picture for Unique<u8> or NonNull<u8>.

Containment at L1

vec
Lowercase private field inside String holding its UTF-8 bytes through a Vec of bytes.

Example: for String::from("Hi"), this field's Vec has length 2 and points to buffer containing bytes H and i.

Vec, written Vec<u8>
Vec is Rust list type whose length can change. Written form Vec<u8> says each list element has type u8, Rust byte-sized number type. The diagram shows only the bare name.

Example: vec![72_u8, 105_u8] constructs Vec<u8> containing byte values for Hi.

Macro
Rust construct that compiler expands into other Rust code during compilation. Macro calls use exclamation mark after name.

Example: vec![1, 2, 3] is call to macro named vec!.

TypeScript relationship: TypeScript has no direct language feature with Rust's macro-call syntax.

vec!
Macro that constructs Vec; it is different from lowercase field vec and uppercase type Vec.

Example: vec![1, 2, 3] constructs list with three number values.

u8
Rust type for whole number from 0 through 255. It occupies exactly one byte.

Example: 72_u8 is byte value for ASCII H; suffix _u8 tells Rust its type.

buf
Short for buffer. Field inside Vec that owns reserved memory block.

Example: at L1, buf owns room for eleven bytes.

RawVec
Private standard-library layer recording buffer pointer and capacity. Outer Vec separately records length.

Example: screenshot places RawVec around inner, while len 11 remains outside it.

inner
Field name meaning next private layer inside RawVec.

Example: inner contains fields ptr and cap.

RawVecInner
Private standard-library type grouping pointer and capacity used by RawVec.

Example: at L1, its pointer reaches heap text and its capacity is 11.

ptr
Short for pointer. Field holding pointer wrapper.

Example: following nested value inside ptr reaches heap byte H.

Unique
Private pointer wrapper telling standard-library code to treat allocation as owned through this path. Ordinary Rust code cannot name it without opting into unstable compiler features.

Example: Unique is wrapper on route from s to its byte buffer.

pointer inside Unique
Field containing next wrapper, NonNull. It is not second allocation.

Example: expanded box reads Unique, then pointer, then NonNull around same route to heap.

NonNull
Pointer wrapper guaranteeing contained pointer is not null, meaning not “points nowhere.” Unlike the other wrappers in this chain, NonNull is part of Rust's public standard library rather than a private detail, so ordinary Rust code may use it directly. It does not by itself guarantee target has not been deallocated.

Example: at L1, NonNull contains pointer dot leading to live text buffer.

pointer inside NonNull
Deepest displayed field containing actual pointer mark ●.

Example: at L4, this deepest field shows ⦻ instead, because its target is gone.

cap
Short for capacity. Field records how many bytes fit before another allocation is needed.

Example: cap 11 is full when len 11; adding one byte requires more room.

usize
Rust type for non-negative whole numbers used as lengths and index positions. Largest possible value depends on computer where program runs.

Example: end position 5 in 0..5 can be represented as usize.

UsizeNoHighBit
Private number wrapper used for capacity. Bit means one binary digit, either 0 or 1; this wrapper only accepts numbers whose highest bit is 0.

Example: UsizeNoHighBit / 11 wraps capacity number 11.

Type / value
Aquascope display notation, not Rust source syntax. Text before slash is type and text after slash is current value.

Example: UsizeNoHighBit / 22 means wrapper type currently contains 22.

len
Short for length. For String, it counts UTF-8 bytes currently used.

Example: len changes from 11 to 12 after adding !; one-character text é has byte length 2.

Do not memorize this wrapper chain. Stable idea is only: String owns heap bytes and records pointer, length, and capacity.

R, W, O permission marks, which the opening diagram does not show

Do not look for this section's marks in the opening diagram. That widget is configured to draw running data only. It contains no R, W, or O letter anywhere, and no amount of pressing its controls will produce one.

Read this section when the book reaches References Change Permissions on Places, where diagrams do carry these marks. This section previews only permission marks listed here; later diagrams may introduce additional icons that their surrounding book text explains. Glyph descriptions come from current Aquascope permission renderer, not opening runtime widget; check them against chapter 4 diagram when you reach it.

These marks describe a compile-time picture, not runtime memory. A place is specific data location named by code: whole variable, field, indexed element, or target reached through reference. Permission is Aquascope's letter for operation compiler currently allows at one place and one source position.

Example: s is place for whole String; s[0..5] is place for selected text range. Same place can have different permissions before and during borrow.

TypeScript relationship: TypeScript has no direct R, W, O permission model.

R: Read
Permission to read data.

Example: evaluating s.len() reads s without changing its text.

W: Write
Permission to mutate data.

Example: s.push_str("!") needs W because text differs afterward.

O: Own
Permission to move or drop owned data. Letter means “own,” not “object.”

Example: drop(s) needs O because it moves and ends String.

+R, +W, +O
Place gains shown permission after source line.

Example: let mut s = ... creates mutable initialized variable, so picture can show +R+W+O.

Slashed letter
Place loses shown permission after source line.

Example: while reference to s's data will be used later, s loses W and O.

‒
Place lacks that permission and line did not change absence.

Example: variable declared without mut can show dash where W would appear.

Filled expected letter
Operation needs permission and place has it.

Example: s.len() can show filled R when reading is allowed.

Hollow expected letter
Operation needs permission but place lacks it, so compiler reports error.

Example: push_str can show hollow W when later reference use keeps s borrowed.

Permission example without new syntax

This is a new compiled program with chapter 4 permission model applied to it, not source copied from rendered Aquascope permission diagram.

fn main() {
    let mut word = String::from("Hello");
    let first = &word[0..1];
    let count = first.len();
    word.push_str("!");
}
  1. word starts with RWO.
  2. Reference first temporarily removes W and O from word.
  3. first.len() is last use of reference, so borrow ends after this statement.
  4. word regains W and O, so push_str is allowed.

This version compiles. rustc reports only warning: unused variable: `count`.

Rejected example: move word.push_str("!") before let count = first.len();. Later read through first keeps borrow active, so word lacks W where push_str needs it. rustc then reports error[E0502]: cannot borrow `word` as mutable because it is also borrowed as immutable.

Check this section

What do R, W, and O permit, and which diagrams carry them?

Reveal feedback

R reads, W mutates, and O moves or drops. They appear in chapter 4 permission diagrams, never in the opening diagram.

Check the decoder

Answer before opening feedback. Every question here is about the opening diagram.

  1. Does Rust code explicitly call main() to start this executable?
  2. What does “binding” mean after let s = ...?
  3. What exact before-and-after effect makes s.push_str("!") mutation?
  4. Why is Rust move not TypeScript assignment?
  5. After let b = a;, when does a stay usable and when does it not?
  6. If drop(s); were deleted from the sample, when would the heap buffer be deallocated?
  7. What is difference among vec, Vec, and vec!?
  8. At L1, which view shows s's length and capacity, and where are its text bytes?
  9. Why can hello show ⦻ at L3 without this program reading invalid memory?
  10. How many lines does the copy icon place on your clipboard?
Reveal feedback
  1. No. Starting executable automatically makes initial call to main.
  2. Connection from variable name s to String value.
  3. Before call text is Hello world, length is 11, and capacity is 11. Afterward text is Hello world!, length is 12, and this run's capacity is 22. Aquascope shows old allocation deallocated after eleven bytes are copied and ! is appended.
  4. Move of non-Copy value makes old Rust variable unusable; TypeScript assignment leaves source variable usable.
  5. a stays usable when its type is Copy, such as i32. It becomes unusable when its type is not, such as String.
  6. At main's closing brace, because s's scope ends there. drop moves that moment earlier; it is not what causes cleanup.
  7. vec is field, Vec is type, and vec! is macro.
  8. Only the binocular view shows len 11 and cap 11; the compact view shows just s ●. The text bytes are in the heap allocation either way.
  9. Old target was deallocated, but hello is never read after creation.
  10. Six. It copies the hidden fn main() { and } along with the four displayed statements.

Primary sources