Introduction to Rust
Rust is a modern systems programming language that focuses on safety, speed, and concurrency. It was created by Mozilla Research and has quickly become one of the most loved programming languages by developers worldwide.
Key Features of Rust
Memory Safety
Rust's ownership system ensures memory safety without needing a garbage collector.
Zero-Cost Abstractions
High-level features compile down to efficient machine code with no runtime overhead.
Concurrency
Write concurrent code without data races, guaranteed at compile time.
Modern Tooling
Cargo package manager, built-in testing, and excellent documentation.
Your First Rust Program
Let's start with the traditional "Hello, World!" program. This is the simplest Rust program you can write:
Breaking it down:
fn main()- Defines the main function, the entry point of every Rust programprintln!- A macro (note the!) that prints text to the console{}- Curly braces define the function body
Running Your Program
To run a Rust program, you'll need to:
- Install Rust from rustup.rs
- Create a new file called
main.rs - Compile and run with:
rustc main.rs && ./main
cargo for real projects. It's Rust's build system and package manager that makes development much easier.What's Next?
Now that you've written your first Rust program, you're ready to dive deeper into the language. In the next lesson, we'll explore variables, mutability, and data types in Rust.