Reference

Programming languages

Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.

Scope and conventions

TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.

Types & syntax

Read common type names

Rust

i32/u32 are signed/unsigned 32-bit integers; usize indexes sizes. String owns UTF-8 text; &str borrows it. [0_u8; 3] repeats a typed byte three times. Vec<T> is growable.

Fragment

Fragment inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let name: &str = "north";
let owned: String = name.to_owned();
let buffer = [0_u8; 3];
let values: Vec<i32> = vec![2, 5];

Decode punctuation

Rust

:: selects a path; ::<T> supplies a generic type. & borrows; &mut borrows mutably. ! after a name invokes a macro. [..n] excludes n. Single quotes denote a char; double quotes denote text.

Fragment

Fragment; shared borrow ends before mutation.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let mut text = String::new();
let shared = &text;
println!("{shared}");
text.push('x');
let number = "24".parse::<i32>();

Represent a missing value

Rust

Option<T> is either Some(value) or None. A normal &T reference is not nullable. Use pattern matching or Option methods instead of assuming a value is present.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let score: Option<i32> = Some(0);

if let Some(value) = score {
    println!("{value}");
}
let fallback = score.unwrap_or(10);

Define a record with named fields

Rust

struct defines a named record. Field names can use shorthand when a local name matches. Mutating a field requires a mutable binding/access path; pub controls external visibility.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
struct Point {
    x: i32,
    y: i32,
}

let x = 2;
let mut point = Point { x, y: 5 };
point.y = 8;

Unpack multiple values

Rust

Tuple elements can have different types. A pattern unpacks them; .0, .1, etc. access positions directly. A one-element tuple needs a trailing comma, such as (24,).

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let item: (&str, i32) = ("north", 24);
let (name, count) = item;
let first = item.0;

Name alternatives and tagged variants

Rust

An enum names alternatives; each variant can carry different data. match checks exhaustiveness. A plain mode enum and a payload-carrying reply use the same enum mechanism.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
enum Reply {
    Ok(i32),
    Failed(String),
}

let reply = Reply::Ok(24);

Read a type parameter

Rust

A type parameter appears in angle brackets; trait bounds specify available behavior. Many type arguments are inferred. ::<T> explicitly supplies a generic argument at a call site.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
fn identity<T>(value: T) -> T {
    value
}

let count = identity::<i32>(24);
let name = identity("north");

Recognize a behavioral contract

Rust

A trait declares behavior; impl Trait for Type supplies it explicitly. Trait bounds allow static dispatch; &dyn Trait can request dynamic dispatch for compatible traits.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
trait Named {
    fn name(&self) -> &str;
}

struct Place;

impl Named for Place {
    fn name(&self) -> &str {
        "north"
    }
}

Check a type or request a conversion

Rust

as performs supported casts, including potentially lossy numeric casts. TryFrom/TryInto make fallible conversion explicit with Result. Ordinary static types do not use TypeScript-style runtime narrowing.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

src/main.rs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let wide: i64 = 24;
let checked = i32::try_from(wide);

if let Ok(value) = checked {
    println!("{value}");
}