Rust is a compiled language designed for systems programming but useful well beyond it. Its central promise is control over performance and memory without giving up memory safety. The compiler catches many invalid data accesses before a program runs, and Rust does not rely on a garbage collector for that safety. section 1.6 section 1.7.1
Three goals help explain Rust’s design:
- Safety: prevent errors such as dangling pointers and data races. An out-of-bounds access instead stops the program with a panic. section 1.6.1
- Productivity: use compiler messages and cargo to catch mistakes and manage projects. section 1.6.2
- Control: choose how values are stored and shared when their runtime costs matter. section 1.6.3
Start with a small program: create a project with `cargo new`, edit `src/main.rs`, and execute it with `cargo run`. A greeting program uses `let` bindings, an array, a `for` loop, and `println!`. Rust strings use UTF-8, so the greetings can include German and Japanese text. The `!` marks `println!` as a macro. section 1.3.2
Listing 1.1 “Hello World!” in three languages
fn greet_world() {
println!("Hello, world!"); #1
let southern_germany = "Grüß Gott!"; #2
let japan = "ハロー・ワールド"; #3
let regions = [southern_germany, japan]; #4
for region in regions.iter() { #5
println!("{}", ®ion); #6
}
}
fn main() {
greet_world(); #7
}
Follow the complete greeting program from its function definition through iteration and printed output. section 1.3.2
Processing records
A CSV-like penguin example splits lines into fields, trims whitespace, and parses lengths. It introduces method calls, a closure passed to `map`, type inference in `Vec<_>`, and debug output that disappears from the release run. section 1.5
Safety rules become concrete when code fails to compile. Dropping a vector and then printing it produces a “borrow of moved value” error; trying to change the same local value from spawned threads also fails. These messages are clues to investigate, not signs that every software bug is impossible. section 1.6.1 section 1.8.5
Rust suits command-line utilities that need quick startup, low memory use, and easy distribution. It also appears in data processing, server applications, constrained devices, and operating-system work. It is not always the easiest choice: cyclic structures can be awkward, the compiler is strict, and the language takes time to learn. Start with a small subset and add features as needed. section 1.10.1 section 1.8.4 section 1.8.1





