86 cards across 4 sections
cargo
rustfmt
clippy
1.98.0
NumBuffer
substr_range
subslice_range
strip_circumfix
Atomic::from_mut
1.98.1
rustc
drop
Copy
String
i32
.clone()
&mut T
&T
Drop::drop
'a
fn f<'a>(x: &'a str) -> &'a str
&self
'static
fn largest<T: PartialOrd>(list: &[T]) -> &T
struct Pair<T> { a: T, b: T }
<T: Display + Clone>
where T: Display, U: Clone
trait Shape { fn area(&self) -> f64; }
impl Shape for Circle { ... }
trait Iterator { type Item; fn next(&mut self) -> Option<Self::Item>; }
impl<T: Display> ToString for T
.to_string()
Display
Box<dyn Shape>
Shape
fn make() -> impl Iterator<Item = i32>
Box<dyn Trait>
#[derive(Debug, Clone, PartialEq)]
enum Direction { North, South, East, West }
Move { x: i32, y: i32 }
Option<T>
Some(T)
None
match
if let Some(x) = opt { ... }
while let
let (x, y) = point;
let Point { x, .. } = p;
if
Some(n) if n > 0 =>
matches!(value, Pattern)
bool
Result<T, E>
Ok(T)
Err(E)
?
Result
Option
panic!
enum
std::error::Error
Debug
From<OtherError> for MyError
.unwrap()
Err
.expect("msg")
source()
Box<dyn Error>
fn next(&mut self) -> Option<Self::Item>
Iterator
.map()
.filter()
.take()
.zip()
Fn
FnMut
FnOnce
.collect()
.collect::<Vec<_>>()
iter()
iter_mut()
into_iter()
T
.sum()
Box<T>
Rc<T>
Arc<T>
RefCell<T>
.borrow()
.borrow_mut()
Weak<T>
Rc::downgrade
thread::spawn
std::sync::mpsc::channel()
Mutex<T>
.lock().unwrap()
Cargo.toml
cargo add
cargo build
cargo publish
mod
pub
use
#[test]
cargo test
assert!
assert_eq!
assert_ne!
async fn
Future
tokio
.await
unsafe { }
2015
2018
2021
2024
fn read() -> Result<String, io::Error> { let s = fs::read_to_string("f")?; Ok(s)}
for i in 0..len
let sum: i32 = nums.iter() .filter(|&&n| n > 0) .sum();
Arc
Mutex
let data = Arc::new(Mutex::new(0));let d2 = Arc::clone(&data);thread::spawn(move || { *d2.lock().unwrap() += 1;});
struct UserId(u64);
struct OrderId(u64);
u64
struct UserId(u64);struct OrderId(u64);fn charge(order: OrderId) { /* ... */ }
&str
&[T]
Vec<T>
fn print_name(name: &str) { println!("{name}");}print_name(&user.name);
cargo clippy -- -D warnings
fn print_all(items: impl Iterator<Item = String>)
fn print_all(items: impl Iterator<Item = String>) { for i in items { println!("{i}"); }}
let Some(user) = find_user(id) else { return ... };
user
let Some(user) = find_user(id) else { return Err("not found".into());};
Order
enum Order { Pending, Shipped { tracking: String }, Delivered,}
match code { 200..=299 => ..., 400..=499 => ..., _ => ... }
match code { 200..=299 => "ok", 400..=499 => "client error", _ => "unknown",}
fn greet(name: &str) -> String { format!("Hi, {name}")}
thiserror
Error
#[error("...")]
#[derive(thiserror::Error, Debug)]enum MyError { #[error("not found")] NotFound,}
anyhow::Result<T>
main
fn main() -> anyhow::Result<()> { let s = std::fs::read_to_string("f")?; Ok(())}
#[derive(Debug, Clone, PartialEq)]struct Point { x: i32, y: i32 }
RefCell
let cell = RefCell::new(5);*cell.borrow_mut() += 1;
if let
Rc<RefCell<T>>
#[allow(...)]
std::thread::sleep
std::sync::Mutex
tokio::time::sleep
tokio::sync::Mutex
spawn_blocking
main.rs
unsafe
// SAFETY:
(a - b).abs() < f64::EPSILON
Result<T, String>
.expect()
Drop
std::mem::forget
std::sync::OnceLock
LazyLock
#[allow(lint)]
edition = "2021"
"2024"