I’m reading the Rust Book.
main
function is special: it’s always the first code that runs in every executable Rust program!
means that you’re calling a *macro*
instead of a normal function; macros don’t always follow the same rules as functions, and they return code instead of returning data. Macros are often used to simplify common patterns.println!("Hello, world!");
// println! is a macro, not a normal function
Cargo is the Rust package manager.
cargo new
to create a new project
--lib
to create a library--bin
is the default project type, which is a standalone application (a “binary”)cargo build
to build the project
./target/debug/
cargo build --release
to compile with optimizations (will be slower!)cargo run
to run the executable directly in one single command
main
function in order to have something to run…cargo test
to execute the test suite.cargo check
is a quick way to make sure the code compiles (without producing an executable).cargo fmt
to format the source code according to the official Rust style guide.cargo doc --open
to view the docs related to all your project’s dependencies.use
statement to import a library explicitly (e.g. use std::io;
)prelude
is Rust’s standard library that is implicitly imported into the scope of every program. It contains many common types, functions, and macros (e.g. println!
) that provide a lot of functionality for writing Rust programs.