Your First Program: Hello World
Your First Program: Hello World
Let’s begin with the canonical starting point: a minimal standalone Rust source file.
Direct Compilation with rustc
Create a file named main.rs:
// main.rs
fn main() {
println!("Hello, world!");
}Compile and run directly using rustc:
rustc main.rs
./mainOutput:
Hello, world!
Deconstructing the Program
fn main() { ... }: Themainfunction is the entry point of every executable Rust program. It takes no arguments and returns unit().println!(...): In Rust, names ending in an exclamation mark!invoke macros rather than standard functions.println!parses format strings at compile time to ensure type safety.