The program starts at main
An executable Rust program begins in a function named main. The body is a block. This one prints a single line and then ends.
fn main() {
println!("The bridge holds.");
}
What to notice. fn names a function. The empty parentheses mean main takes no arguments. The programs on this page are Rust 2024.
Try itprintln! fills a placeholder
println! is a macro, which is why the name ends in !. Braces in the string are a placeholder. The matching name is filled in when the line runs.
fn main() {
let span = 12;
println!("Span: {span} meters");
}
What to notice. The braces are not printed. {span} is replaced by the value of the binding span.
Try itThe Cargo shape
A real package is a directory. Cargo.toml names it. src/main.rs holds the program. Cargo reads that layout when you build.
// ferrugo-bridge/
// ├── Cargo.toml
// └── src/
// └── main.rs
fn main() {
println!("cargo run");
}
What to notice. Cargo.toml is the manifest. src/main.rs is the binary crate root. Comments with // are not executed.
This site does not run Cargo. Try it opens the program that would live in src/main.rs. On your own machine, cargo run builds and runs the package.
Try it