Rust Language Features
Core Rust programming language concepts: ownership, borrowing, lifetimes, traits, and concurrency.
Core Rust programming language concepts: ownership, borrowing, lifetimes, traits, and concurrency.
| Name | Category | Description | Example |
|---|---|---|---|
| Ownership | Memory Management | Each value has a single owner; when owner goes out of scope, value is dropped. | let s1 = String::from("hello"); let s2 = s1; // s1 is no longer valid |
| Borrowing | Memory Management | References (&) allow you to refer to some value without taking ownership. | let r = &s; // immutable borrow let r_mut = &mut s; // mutable borrow (exclusive) |
| Lifetimes | Memory Management | Annotations ensure all references are valid; compiler enforces lifetime rules. | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } } |
| Traits | Abstraction | Define shared behavior; similar to interfaces in other languages. Use generics with trait bounds. | trait Summary { fn summarize(&self) -> String; } impl Summary for NewsArticle { ... } |
| Pattern Matching | Control Flow | Match expressions check enum variants, destructure structs, and bind variables. | match value { Some(x) => x, None => 0, Err(e) => panic!("{}", e) } |
| Concurrency (Fearless) | Concurrency | Thread-safe by compile-time checks: Send and Sync traits guarantee no data races at runtime. | let handle = thread::spawn(|| { for _ in 0..10 { println!("thread"); } }); handle.join().unwrap(); |
| Error Handling (Result<T,E>) | Error Handling | Enums Result<T,E> and Option<T> force explicit handling; no null or unchecked exceptions. | let f: Result<File> = File::open("file.txt"); match f { Ok(file) => ..., Err(e) => eprintln!("{}", e) } |
| Zero-Cost Abstractions | Performance | High-level constructs compile to assembly as efficient as hand-written C; no runtime overhead. | Iterators: v.iter().map(|x| x * 2).filter(|x| x > 10).collect::<Vec<_>>(); |
The static files are identical to what the API returns, but with no rate limit and no server round trip. Use the API when you want a query and a content type; use the files when you want to cache one document.
curl "https://yjtoon.com/api/dataset/rust-language-features?format=toon"
const res = await fetch( "https://yjtoon.com/static-data/dataset/rust-language-features.toon" ); const toon = await res.text();
Rate limit: 120 requests per minute per IP, no key and no signup. API reference →