Rust-Cheatsheet

๐Ÿ‘‹ Hello World fn main() { println!("Hello, world!"); } ๐Ÿ’ก Tip: Use println! macro for output in Rust. ๐Ÿ“ฆ Variables & Data Types fn main() { let age: i32 = 21; let pi: f64 = 3.14159; let grade: char = 'A'; let name: &str = "Maxon"; println!("{} is {} years old.", name, age); } ๐Ÿ’ก Tip: Variables are immutable by default. Use mut for mutability. ๐Ÿ”€ Control Flow fn main() { for i in 1..=5 { if i % 2 == 0 { println!("{} is even", i); } else { println!("{} is odd", i); } } } ๐Ÿ’ก Tip: Use if , else if , match , loop , and while for control flow. ๐Ÿ›  Functions fn add(a: i32, b: i32) -> i32 { a + b } fn main() { println!("Sum: {}", add(5, 3)); } ๐Ÿ’ก Tip: Functions return the last expression automatically (no return needed). ๐Ÿ— Structs struct Car { brand: String, speed: u32, } impl Car { fn drive(&self) { println!("{}…

Post a Comment