Reading — step 1 of 5
Learn
Hello, World
Rust's pitch is a bargain: accept a compiler that argues with you, and in exchange your programs don't crash at 3 a.m. This course is about learning to win those arguments — and it starts, as always, with the smallest program that compiles:
fn main() {
println!("Hello, World");
}
Small, but three things in it deserve a first-day look:
fn main()— every Rust binary starts here.fndeclares a function; the body is the{}block.println!— that!is not decoration. It marks a macro, not a function: code that generates code at compile time.println!inspects its format string during compilation, which is why a mismatched placeholder is a compile error in Rust rather than garbage output at runtime. For now the practical rule is simply: printing uses!.- Statements end with
;— and (foreshadowing) the places where Rust omits semicolons turn out to be a feature, not sloppiness. That story pays off in the Functions lesson.
Run it
$ rustc main.rs && ./main # bare compiler
Hello, World
$ cargo run # what real projects use
rustc is the compiler; Cargo is the build tool + package manager wrapped around it (cargo new, cargo run, cargo test), and effectively all Rust development happens through it. Like Go, the output is a single native binary — no runtime to install, no VM. Unlike almost everything else, that binary was vetted by the borrow checker (chapter 4's headline act) before it was allowed to exist.
Meet your co-author: the error messages
Break the program on purpose — misspell the macro:
error: cannot find macro `printn` in this scope
--> main.rs:2:5
|
2 | printn!("Hello, World");
| ^^^^^^ help: a macro with a similar name exists: `println`
Read it top to bottom: what went wrong, exactly where (file, line, column, with the offending code drawn and underlined), and a suggested fix that is usually correct. Rust's error messages are widely considered the best in the industry, and working with them — not around them — is the actual skill this course teaches. When an error appears: read the whole message, including the help: line, before touching the code. Half your future debugging sessions end right there.
Warnings have opinions too
Compile a program with an unused variable and Rust doesn't error (unlike Go) — it warns, loudly and specifically, and idiomatic projects treat warnings as failures. The compiler also nags about style (snake_case for functions and variables, CamelCase for types) — the community tool rustfmt (via cargo fmt) settles formatting exactly the way gofmt does for Go: one style, no debates.
Your exercise
Print the exact requested text. Byte-exact grading applies: println! adds the newline (don't add another), capitalization and punctuation must match, and print! (no ln) exists when you don't want the newline. Type it out — fn main, the !, the semicolon. This skeleton is the outermost layer of every Rust program you'll ever write, and your hands should know it before your eyes stop noticing it.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…