Introduction
Rust is a compiled, statically typed language designed for performance on par with C and C++, but with a compiler that catches memory errors — the kind that cause crashes and security vulnerabilities in those languages — before your program ever runs.
Why Rust exists
C and C++ give you full control over memory, but that control is also where most of their worst bugs come from — reading freed memory, writing past the end of a buffer, forgetting to free something at all. Rust's answer is the borrow checker: a part of the compiler that tracks, for every value in your program, exactly who owns it and who's allowed to look at it right now. You'll spend real time with this in the Ownership & Borrowing lesson — for now, just know it's the reason Rust code that compiles tends to simply work.
Installing Rust and creating a project
Rust is installed via rustup, which manages the compiler (rustc) and Rust's build tool and package manager, cargo. Almost all real Rust work goes through cargo rather than calling rustc directly:
$ cargo new hello_world $ cd hello_world $ cargo run
Compiling hello_world v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
Running `target/debug/hello_world`
Hello, world!cargo new scaffolds a whole project — a Cargo.toml file describing it, and a src/main.rs file with a working "Hello, world!" already in it. cargo run compiles and runs it in one step, recompiling automatically whenever the source changes.
Anatomy of a Rust program
fn main() { println!("Hello, world!"); }
Hello, world!
fn main() defines the function every Rust executable starts running from, same as in C. println! — note the exclamation mark — isn't an ordinary function call, it's a macro, which is why it looks slightly different from everything else you'll call in this course. Every statement inside the function body ends with a semicolon.
cargo build compiles without running, producing a binary in target/debug/; cargo run does both. Add --release to either command for an optimized build in target/release/ — debug builds compile faster but run slower, and also include extra runtime checks (like the integer overflow check you'll see in the Operators lesson) that release builds skip for speed.