Click a card to flip it · 8 terms
The special characters you'll see in almost every Rust file. Knowing what each one means by sight will make reading code much faster.
Propagates an error to the caller if the result is Err
Err
When calling a function that returns Result or Option
Result
Option
let data = read_file(path)?;// returns Err up if it fails
Navigates into a type, module, or enum to access items inside
Calling associated functions or accessing enum variants
let s = String::from("hi");let v = Vec::new();
Separates a match pattern from the code that runs for that case
Inside a match block, one per case
match
match coin { Heads => 1,Tails => 0 }
Wraps a closure's parameters; defines an inline anonymous function
Passing logic to iterators like map or filter
map
filter
let double = |x| x * 2;double(5) // returns 10
An exclusive range: start up to but not including end
Looping over a count or slicing a collection
for i in 0..5 {// i = 0, 1, 2, 3, 4
An inclusive range: start through and including end
When you need to include the last value in a range
for i in 0..=5 {// i = 0, 1, 2, 3, 4, 5
An attribute that tells the compiler how to handle the next item
Deriving traits or marking types for special behavior
#[derive(Debug, Clone)]struct Point { x: i32 }
Makes an item visible and usable outside its current module
When a function, struct, or field needs to be public
pub fn transfer() { }pub struct Account { }