Rust quick reference

Runs in Zerethon IDE · Rust 1.87 Official Rust documentation ↗

Rust 1.87 (edition 2024) essentials: variables and types, control flow, functions, ownership and borrowing, structs, enums and traits, Option and Result, collections, strings, input and files — and how a Rust program is compiled and run in Zerethon IDE.

Written for Rust 1.87. Examples that show an output were run in the Zerethon sandbox (Rust 1.87) on 2026-10-24.

Basics

  • Hello, World

    The smallest Rust program: fn main() and the println! macro.

  • Variables and types

    let and let mut, the number types, String and &str, constants, shadowing, and parsing text into numbers.

  • Conditions and loops

    if as an expression, match, and the three loops: for over a range or iterator, while, and loop with break value.

  • Functions and closures

    Define functions with fn, typed parameters and return values, tuples, and closures.

  • Ownership and borrowing

    Each value has one owner; pass & to lend it, &mut to let a function change it, and .clone() to copy it.

Data

  • Vectors, arrays and hash maps

    Vec, slices, HashMap with the entry API, sorting, and iterator chains with filter, map and collect.

  • Structs, enums and traits

    Define data with struct and enum, add methods in impl, share behaviour with traits, and derive Debug.

  • Option, Result and the ? operator

    Values that may be missing (Option) and operations that may fail (Result), handled with match, if let, unwrap_or and ?.

  • Strings

    String and &str, common methods, formatting, characters vs bytes, and splitting text.

Input and files

  • Reading input (stdin)

    Read what you type in the IDE's Input tab with read_line or lines().

  • Reading and writing files

    Read project files with fs::read_to_string, return io::Result from main, and write temporary files under /tmp.

  • Modules and several files

    Split a program into files with mod, make items visible with pub, and what is available without crates.

In Zerethon IDE

  • Running Rust in Zerethon IDE

    What Run compiles, the time limit, input, tests, and what a run cannot do.

  • Common errors

    Compiler errors such as E0382 use of moved value, E0502, E0308 mismatched types, and panics such as index out of bounds and unwrap on None.

  • Official documentation

    Where to read more: the Rust book, Rust by Example, the standard library and the error index.

References