Rust Language Features

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

  • JSON6,577 B
  • YAML4,849 B · −26%
  • TOON3,995 B · −39%

Core features of Rust by category: ownership, borrowing and lifetimes for memory safety, traits for abstraction, pattern matching, fearless concurrency, Result-based error handling and zero-cost abstractions, with examples.

Use it when

  • You are learning Rust's model of ownership or comparing it with garbage-collected languages.
  • You need an example of an idiomatic Rust feature.

Watch out for

  • The borrow checker enforces rules at compile time; examples can look simple while hiding lifetime annotations in larger programs.
  • Rust editions (2015, 2018, 2021, 2024) introduce syntax changes that are opt-in per crate.

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<_>>();
Enums and Option<T>Type SystemEnums hold one of several variants and can carry data; Option<T> replaces null with an explicit Some or None.let x: Option<i32> = Some(5); match x { Some(n) => n, None => 0 };
MacrosMetaprogrammingCode that writes code, expanded at compile time, such as macro_rules! and derive attributes.#[derive(Debug, Clone)] struct Point { x: i32, y: i32 }
Iterators and ClosuresFunctionalLazy iterator adapters combined with closures compile to loops as fast as hand-written ones.let evens: Vec<i32> = (1..10).filter(|n| n % 2 == 0).collect();
Smart PointersMemory ManagementTypes such as Box, Rc and Arc that own heap data and manage sharing and lifetime.let shared = std::sync::Arc::new(5);

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
featuresnamestringOwnership
featurescategorystringMemory Management
featuresdescriptionstringEach value has a single owner; when owner goes …
featuresexamplestringlet s1 = String::from("hello"); let s2 = s1; //…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

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

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets