Lets Get Rusty Cheat Sheet
Lets Get Rusty Cheat Sheet
Table of Contents
match shape {
Shape::Rectangle { x, y } => //...
Shape::Circle(radius) => //...
}
Pattern Matching
Basics Ignoring values
Error Handling
Iterators
Throw unrecoverable error
Usage
panic!("Critical error! Exiting!");
// Methods that consume iterators
let v1 = vec![1, 2, 3];
let v1_iter = v1.iter(); Option enum
let total: i32 = v1_iter.sum(); fn getUserId(username: &str) -> Option<u32>
{
// Methods that produce new iterators if database.userExists(username) {
let v1: Vec<i32> = vec![1, 2, 3]; Some(database.getIdForUser(username))
let iter = v1.iter().map(|x| x + 1); }
pub fn some_function() {
my_module::my_function();
}
// src/my_module.rs
pub fn my_function() {}