Ultimate Rust Crash Course !!hot!! May 2026

fn main() let x = 5; // immutable // x = 6; // ERROR: cannot assign twice to immutable variable let mut y = 10; // mutable y = 11; // OK

let x = 5; let x = x + 1; // shadows previous x { let x = x * 2; println!("Inner: {}", x); // 12 } println!("Outer: {}", x); // 6 Shadowing lets you change type without renaming: ultimate rust crash course

let mut s = String::from("hello"); change(&mut s); fn main() let x = 5; // immutable

By the end of this article, you will read and write basic Rust, understand ownership, and be ready to tackle real projects. Most bugs come from memory errors (use-after-free, dangling pointers, data races) or concurrency issues. Languages like C/C++ give you speed but no safety. Languages like Java/Go give you safety but with a garbage collector (GC) that adds runtime overhead. Languages like Java/Go give you safety but with

use std::fs::File; use std::io::ErrorKind; fn main() let greeting_file_result = File::open("hello.txt"); let greeting_file = match greeting_file_result Ok(file) => file, Err(error) => match error.kind() ErrorKind::NotFound => match File::create("hello.txt") Ok(fc) => fc, Err(e) => panic!("Problem creating the file: :?", e), , other_error => panic!("Problem opening the file: :?", other_error);

When a function returns a reference, the lifetime of the output must be tied to one of the inputs.

cargo new hello_rust cd hello_rust cargo run Inside src/main.rs :