Most frustrations with Rust come from fighting the borrow checker. Instead:
This is the one unique concept you must understand.
fn largest<T: PartialOrd + Copy>(list: &[T]) -> T let mut largest = list[0]; for &item in list if item > largest largest = item; ultimate rust crash course
let x = 5; if x > 10 println!("x is greater than 10"); else println!("x is less than or equal to 10");
Traits are also used as on generics.
let s = String::from("hello"); // s is the owner of the string let t = s; // t is now the owner of the string println!("{}", s); // error: use of moved value
let tup: (i32, f64, char) = (500, 6.4, 'R'); let (x, y, z) = tup; // destructuring let first = tup.0; Most frustrations with Rust come from fighting the
// 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