Rust Language Features

Core Rust programming language concepts: ownership, borrowing, lifetimes, traits, and concurrency.

The data

Features

NameCategoryDescriptionExample
OwnershipMemory ManagementEach 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
BorrowingMemory ManagementReferences (&) allow you to refer to some value without taking ownership.let r = &s; // immutable borrow let r_mut = &mut s; // mutable borrow (exclusive)
LifetimesMemory ManagementAnnotations 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 } }
TraitsAbstractionDefine shared behavior; similar to interfaces in other languages. Use generics with trait bounds.trait Summary { fn summarize(&self) -> String; } impl Summary for NewsArticle { ... }
Pattern MatchingControl FlowMatch expressions check enum variants, destructure structs, and bind variables.match value { Some(x) => x, None => 0, Err(e) => panic!("{}", e) }
Concurrency (Fearless)ConcurrencyThread-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 HandlingEnums 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 AbstractionsPerformanceHigh-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<_>>();

Fetch the same bytes

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 →

Topics

  • rust
  • systems
  • programming
  • memory-safety
  • concurrency