Hello Cargo

View saved

Create a project

Cargo makes a folder with Cargo.toml and src/main.rs.

cargo new hello
cd hello

Read the starter program

main is the entry point. println! is a macro that prints a line.

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

Run it

cargo run compiles if needed and executes the binary.

cargo run

Build without running

  • cargo build creates a debug binary in target/
  • cargo build --release optimizes for speed
  • cargo check type-checks faster without full codegen
  • Commit Cargo.toml and source; ignore target/

Comments

One comment per signed-in account. Comments are saved with this page’s URL.