Welcome & Hello World
Rust is a modern systems programming language focused on safety, speed, and concurrency. Developed by Mozilla Research, it achieves memory safety without a garbage collector, making it a powerful replacement for C and C++.
1 Compiling in Rust
Rust is a statically compiled language. It uses `rustc` to compile code down into native binary execution files. Rust is built on three core pillars: memory safety (checked at compile time), absolute zero-cost abstractions, and concurrency free of data races.
2 Writing Hello World: The macro println!
Let's run a classic Hello World program in Rust:
Rust — Hello World
▶ Run Code
fn main() {
println!("Hello, World!");
print!("Welcome to Our Rust Compiler!\n");
}
Let's examine components:
- fn main(): The entry point function for every Rust executable.
- println!: A Rust **macro** (indicated by the exclamation mark `!`) that outputs text and appends a newline. Macros expand code during compiling, enabling compile-time argument checks.
3 Code Challenge
Challenge: Edit the code block. Use `println!` with placeholders (e.g. `println!("Value: {}", 42);`) to print your name and class rating numbers. Run the code.