Rust Programming
Learn systems programming with safety and performance
🦀 Welcome to Rust!
Rust is a systems programming language focused on safety, speed, and concurrency. It prevents common programming errors like null pointer dereferences and buffer overflows while delivering zero-cost abstractions and excellent performance for system-level programming.
fn main() {
println!("Hello, Rust world!");
let message = "Welcome to systems programming!";
println!("{}", message);
}
Output:
Hello, Rust world!
Welcome to systems programming!
Why Choose Rust?
Memory Safety
Prevents crashes and security vulnerabilities
let data = vec![1, 2, 3];
// Rust prevents buffer overflows
Zero-Cost Abstractions
High-level features without runtime overhead
let numbers: Vec = (1..5).collect();
// Iterator chains compile to fast loops
Concurrency
Safe parallel programming without data races
use std::thread;
thread::spawn(|| {
println!("Hello from thread!");
});
Package Manager
Cargo handles dependencies and builds
cargo new my_project
cargo build
cargo run
🔹 What You'll Learn
This tutorial covers everything you need to start programming in Rust:
Tutorial Contents:
- Rust Introduction: Understanding Rust's philosophy and features
- Getting Started: Installing Rust and setting up your environment
- Rust Syntax: Variables, functions, and basic language constructs
- Output: Printing and formatting data in Rust programs
- Comments: Documenting your Rust code effectively
🔹 Your First Rust Program
Let's start with a simple Rust program that demonstrates basic concepts:
fn main() {
// This is a comment
let name = "Rustacean"; // Immutable variable
let mut count = 0; // Mutable variable
println!("Hello, {}!", name);
count += 1;
println!("Count: {}", count);
// Function call
greet_user(name);
}
fn greet_user(user: &str) {
println!("Welcome to Rust, {}!", user);
}
Output:
Hello, Rustacean!
Count: 1
Welcome to Rust, Rustacean!