Glossary

Need to understand Rust terminology? This glossary provides clear definitions with examples for all major Rust concepts.

Ownership Concepts

Borrowing

Definition: Creating a reference to a value without taking ownership.

Example:

let s = String::from("hello");
let r = &s;  // Borrowing s
// s is still valid

See also: Beginner Tutorial - References and Borrowing


Clone

Definition: Creating a deep copy of a value, including heap data.

Example:

let s1 = String::from("hello");
let s2 = s1.clone();  // Deep copy
// Both s1 and s2 are valid

See also: Beginner Tutorial - Ownership System


Copy

Definition: Trait for types that can be duplicated by copying bits (stack-only types).

Example:

let x = 5;
let y = x;  // x is copied, not moved
// Both x and y are valid

Types implementing Copy: Integers, floats, booleans, chars, tuples of Copy types.


Drop

Definition: Trait that runs cleanup code when a value goes out of scope.

Example:

impl Drop for MyStruct {
    fn drop(&mut self) {
        println!("Dropping MyStruct");
    }
}

See also: Advanced Tutorial - Memory Layout


Lifetime

Definition: Scope for which a reference is valid. Ensures references don’t outlive their data.

Example:

fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() { x } else { y }
}

See also: Intermediate Tutorial - Lifetimes


Move

Definition: Transferring ownership of a value from one variable to another.

Example:

let s1 = String::from("hello");
let s2 = s1;  // s1 is moved to s2
// s1 is no longer valid

Ownership

Definition: System where each value has a single owner responsible for deallocating it.

Rules:

  1. Each value has an owner
  2. Only one owner at a time
  3. Value dropped when owner goes out of scope

See also: Beginner Tutorial - Ownership System


Reference

Definition: Pointer to a value without owning it. Written as &T (immutable) or &mut T (mutable).

Example:

let s = String::from("hello");
let r = &s;  // Immutable reference

Type System

Associated Type

Definition: Type placeholder in a trait, specified by implementer.

Example:

trait Iterator {
    type Item;
    fn next(&mut self) -> Option<Self::Item>;
}

impl Iterator for Counter {
    type Item = u32;
    // ...
}

See also: Advanced Tutorial - Advanced Traits


Generic

Definition: Code that works with multiple types, specified by type parameters.

Example:

fn largest<T: PartialOrd>(list: &[T]) -> &T {
    // Works with any T that implements PartialOrd
}

See also: Intermediate Tutorial - Generics


Monomorphization

Definition: Process where compiler generates specialized code for each concrete type used with generics.

Result: Zero-cost abstractions - generics have no runtime overhead.


Phantom Type

Definition: Type parameter that doesn’t appear in struct fields but provides compile-time type checking.

Example:

struct PhantomData<T>;

struct Distance<Unit> {
    value: f64,
    _marker: PhantomData<Unit>,
}

See also: Advanced Tutorial - Advanced Traits


Trait

Definition: Collection of methods defining shared behavior, similar to interfaces.

Example:

trait Summary {
    fn summarize(&self) -> String;
}

See also: Intermediate Tutorial - Traits


Trait Bound

Definition: Constraint on generic type parameter requiring it implements specific traits.

Example:

fn notify<T: Summary>(item: &T) {
    // T must implement Summary
}

Trait Object

Definition: Dynamic dispatch using dyn Trait allowing different concrete types at runtime.

Example:

let objects: Vec<Box<dyn Draw>> = vec![
    Box::new(Button { }),
    Box::new(SelectBox { }),
];

Zero-Sized Type (ZST)

Definition: Type occupying no memory at runtime.

Example:

struct Nothing;  // ZST
PhantomData<T>   // ZST

Use cases: Marker types, phantom data, type-state pattern.


Memory Concepts

Arc

Definition: Atomically Reference Counted smart pointer for thread-safe shared ownership.

Example:

use std::sync::Arc;

let data = Arc::new(vec![1, 2, 3]);
let data_clone = Arc::clone(&data);
// Thread-safe shared ownership

See also: Intermediate Tutorial - Smart Pointers


Box

Definition: Smart pointer for heap allocation.

Example:

let b = Box::new(5);  // 5 allocated on heap

Use cases: Large values, recursive types, trait objects.


Heap

Definition: Memory region for dynamic allocation, slower than stack.

Characteristics: Variable size, manual management (Rust automates via ownership).


Rc

Definition: Reference Counted smart pointer for shared ownership (single-threaded).

Example:

use std::rc::Rc;

let a = Rc::new(5);
let b = Rc::clone(&a);
// Shared ownership, single-threaded

RefCell

Definition: Type providing interior mutability with runtime borrow checking.

Example:

use std::cell::RefCell;

let x = RefCell::new(5);
*x.borrow_mut() += 1;  // Mutate through immutable reference

Stack

Definition: Memory region for fixed-size values, fast LIFO allocation.

Characteristics: Fixed size, automatically managed, limited space.


Concurrency

Atomic

Definition: Operation completing in single step, preventing data races.

Example:

use std::sync::atomic::{AtomicUsize, Ordering};

let counter = AtomicUsize::new(0);
counter.fetch_add(1, Ordering::SeqCst);

Channel

Definition: Message-passing mechanism for thread communication.

Example:

use std::sync::mpsc;

let (tx, rx) = mpsc::channel();
tx.send("message").unwrap();
let msg = rx.recv().unwrap();

See also: Intermediate Tutorial - Concurrency


Mutex

Definition: Mutual exclusion lock protecting shared data.

Example:

use std::sync::Mutex;

let m = Mutex::new(5);
let mut num = m.lock().unwrap();
*num = 6;

Send

Definition: Trait for types safe to transfer ownership between threads.

Characteristics: Almost all types are Send. Notable exception: Rc<T>.


Sync

Definition: Trait for types safe to reference from multiple threads.

Characteristics: &T is Send if T is Sync.


Thread

Definition: Unit of execution running concurrently with other threads.

Example:

use std::thread;

let handle = thread::spawn(|| {
    println!("Hello from thread");
});
handle.join().unwrap();

Async Concepts

async

Definition: Keyword creating asynchronous function returning a Future.

Example:

async fn fetch_data() -> String {
    // Asynchronous work
    String::from("data")
}

See also: Intermediate Tutorial - Async/Await


await

Definition: Keyword suspending execution until Future completes.

Example:

let data = fetch_data().await;

Executor

Definition: Runtime component executing async tasks.

Examples: Tokio, async-std, smol.


Future

Definition: Value representing computation that may not have completed yet.

Trait:

trait Future {
    type Output;
    fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output>;
}

Pin

Definition: Type preventing value from being moved in memory.

Use case: Required for self-referential futures.


Runtime

Definition: Async executor environment managing task scheduling.

Example: Tokio runtime executes async tasks.


Tokio

Definition: Popular async runtime for Rust.

Example:

#[tokio::main]
async fn main() {
    // Async code
}

Macro Concepts

Declarative Macro

Definition: Pattern-matching macro created with macro_rules!.

Example:

macro_rules! say_hello {
    () => {
        println!("Hello!");
    };
}

See also: Advanced Tutorial - Declarative Macros


Derive Macro

Definition: Procedural macro generating trait implementations.

Example:

#[derive(Debug, Clone)]
struct Point {
    x: i32,
    y: i32,
}

Hygiene

Definition: Property where macro variables don’t conflict with surrounding code.

Result: Macros can’t accidentally capture external variables.


Procedural Macro

Definition: Macro operating on Rust syntax tree, generating code.

Types:

  • Derive macros: #[derive(MyTrait)]
  • Attribute-like: #[route(GET, "/")]
  • Function-like: sql!("SELECT ...")

See also: Advanced Tutorial - Procedural Macros


Cargo Concepts

Crate

Definition: Compilation unit in Rust - library or binary.

Types:

  • Binary crate: Executable program (has fn main)
  • Library crate: Reusable code (no fn main)

Dependency

Definition: External crate your project uses.

Specified in: Cargo.toml under [dependencies]

[dependencies]
serde = "1.0"

Feature

Definition: Optional functionality in a crate.

Example:

[dependencies]
tokio = { version = "1", features = ["full"] }

Package

Definition: Bundle of one or more crates with Cargo.toml.

Can contain:

  • At most one library crate
  • Any number of binary crates

Workspace

Definition: Set of packages sharing Cargo.lock and output directory.

Structure:

[workspace]
members = [
    "crate1",
    "crate2",
]

Compiler Concepts

Borrow Checker

Definition: Compiler component enforcing ownership and borrowing rules.

Prevents: Use-after-free, double-free, data races.


MIR (Mid-level Intermediate Representation)

Definition: Simplified representation of Rust code used for optimization and borrow checking.

Purpose: Easier to analyze than full syntax tree.


NLL (Non-Lexical Lifetimes)

Definition: Borrow checker improvement allowing references to end before scope ends.

Example:

let mut s = String::from("hello");
let r = &s;
println!("{}", r);
// r no longer used, can mutably borrow now
let r2 = &mut s;

Pattern Matching

Destructuring

Definition: Breaking complex value into parts.

Example:

let (x, y, z) = (1, 2, 3);

match point {
    Point { x, y } => println!("{}, {}", x, y),
}

Exhaustiveness

Definition: Requirement that match expressions cover all possible cases.

Enforced by: Compiler ensures all enum variants handled.


Guard

Definition: Additional condition in match arm.

Example:

match num {
    x if x < 5 => println!("less than 5"),
    x => println!("{}", x),
}

Error Handling

Option

Definition: Enum representing optional value - Some(T) or None.

Use case: Absence of value (not an error).

Example:

fn find_user(id: u32) -> Option<User> {
    // Returns None if not found
}

panic!

Definition: Macro causing program to abort with error message.

Use case: Unrecoverable errors, bugs, invariant violations.


Result<T, E>

Definition: Enum representing success (Ok(T)) or failure (Err(E)).

Use case: Recoverable errors.

Example:

fn parse_number(s: &str) -> Result<i32, ParseIntError> {
    s.parse()
}

unwrap

Definition: Method extracting value from Option or Result, panicking on None/Err.

Use case: Prototyping, testing, when failure is impossible.


?

Definition: Operator propagating errors early from function.

Desugars to:

match result {
    Ok(val) => val,
    Err(e) => return Err(e.into()),
}

Advanced Concepts

Const Generic

Definition: Generic parameter that’s a value, not a type.

Example:

fn print_array<T, const N: usize>(arr: [T; N]) {
    // N is a const generic
}

DST (Dynamically Sized Type)

Definition: Type whose size isn’t known at compile time.

Examples: str, [T], dyn Trait

Usage: Must use through pointer (&str, Box<[T]>, &dyn Trait)


FFI (Foreign Function Interface)

Definition: Mechanism for calling C functions from Rust or vice versa.

Example:

extern "C" {
    fn abs(x: i32) -> i32;
}

See also: Advanced Tutorial - FFI


RAII (Resource Acquisition Is Initialization)

Definition: Pattern where resources acquired in constructor, released in destructor.

Rust implementation: Drop trait.


Type State Pattern

Definition: Using types to represent states, preventing invalid state transitions at compile time.

Example:

struct Locked;
struct Unlocked;

struct Door<State> {
    _state: PhantomData<State>,
}

Unsafe

Definition: Keyword opting out of Rust’s safety guarantees.

Allows:

  • Dereferencing raw pointers
  • Calling unsafe functions
  • Accessing/modifying mutable statics
  • Implementing unsafe traits
  • Accessing union fields

See also: Advanced Tutorial - Unsafe Rust


Related Resources


Master Rust terminology to understand documentation and discussions!

Last updated