Reading The Rust Book from cover to cover — Day 1 — Hello World!

Jaspreet Kaur
2 min readApr 4, 2024

--

Rust Programming Language logo

I have started learning Rust and making notes here for a quick revision later.

Chapter 1: Getting Started

Customary “Hello world!” program. Rust code files end with the extension .rs.

fn main() {
println!("Hello, world!");
}

println! is a macro. Function calls are NOT followed with a ! sign.

Cargo is Rust’s build system and package manager. We can create a project using cargo new.

Cargo.toml uses the TOML (Tom’s Obvious, Minimal Language) format, which is Cargo’s configuration format.

[package]
name = "hello_cargo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies], is the section to list any of your project’s dependencies. In Rust ecosystems, dependencies are called crates.

cargo build — builds the project and creates an executable file in target/debug/ folder. Running cargo build for the first time also causes Cargo to create a new file at the top level: Cargo.lock. This file keeps track of the exact versions of dependencies in your project.

cargo run — to compile the code and then run the resultant executable all in one command.

cargo check — this command quickly checks your code to make sure it compiles but doesn’t produce an executable. cargo check is much faster than cargo build because it skips the step of producing an executable. If you’re continually checking your work while writing the code, using cargo check will speed up the process of letting you know if your project is still compiling!

--

--