What Is Rust?

A systems language with the speed of C and C++ and memory safety checked by the compiler — no garbage collector needed.

Rust is a compiled systems programming language, first released as 1.0 in 2015. It runs as fast as C and C++ and can work without an operating system, but its compiler proves at compile time that programs have no use-after-free, double free, dangling pointers or data races. That is why Linux, Windows, Android, Chromium, AWS and many embedded and automotive projects now use it for new low-level code.

Your first program

fn main() is the entry point.

{language} inserts a variable by name; {} takes the next argument.

{:>8} right-aligns in 8 characters, {:.3} keeps 3 decimals, {:#x} prints hex with 0x.

eprintln! writes to standard error instead of standard output.

The toolchain

println! is a macro, not a function: the ! is required.

How does Rust free memory without a garbage collector?

Every value has exactly one owner; when the owner goes out of scope the value is dropped (freed) automatically. The compiler tracks ownership and borrows, so this is decided at compile time with no run-time collector.

What do cargo build, cargo run and cargo check do?

build compiles the project, run builds and runs it, check only type-checks it (much faster) without generating code.