Ultimate Rust Crash Course ((better)) Page
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:
let mut s = String::from("hello"); change(&mut s); ultimate rust crash course
let home = IpAddrKind::V4(127,0,0,1); let loopback = IpAddrKind::V6(String::from("::1")); Rust has no null . Instead: Option<T> . let x = 5; let x = x
fn largest<T: PartialOrd + Copy>(list: &[T]) -> T let mut largest = list[0]; for &item in list if item > largest largest = item; let x: i32 = 5; let y: Option<i32>
let some_number = Some(5); let absent_number: Option<i32> = None; // You cannot add Option<i32> to i32 directly. let x: i32 = 5; let y: Option<i32> = Some(10); // let sum = x + y; // ERROR: mismatched types