api: "YAML JSON TOON Database" version: 1.0.0 format: json dataset: id: 19 slug: rust-language-features title: "Rust Language Features" description: "Core Rust programming language concepts: ownership, borrowing, lifetimes, traits, and concurrency." category: "Programming Languages" category_slug: programming-languages tags: "rust,systems,programming,memory-safety,concurrency" view_count: 0 created_at: 1777673262 updated_at: 1777673262 data: features [8]{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)","Error Handling","Enums Result and Option force explicit handling; no null or unchecked exceptions.","let f: Result = 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::>();"