Skip to content

Glossary

Each term has a short definition and, where one exists, the nearest Java (or C#) equivalent. “Nearest” is not “same”: read the definition.

Borrow, reference

Access to a value without owning it. A shared reference &T lets you read; a mutable reference &mut T lets you change. At any time a value has either many shared references or one mutable reference. Java: every object variable is a reference, but Java has no rules about who can read or change.

Borrow checker

The part of the compiler that checks that every reference is valid and that the borrow rules hold. Most “fighting the compiler” stories are about it. Java: none.

Cargo

Rust’s build tool and package manager: cargo build, cargo test, cargo add. Java: Maven or Gradle.

Clippy

The official linter, run with cargo clippy. Its lints are grouped: default, pedantic, nursery, and restriction. Java: SpotBugs, Error Prone, or IntelliJ inspections.

Clone

A trait for explicit copies: value.clone(). It can be cheap (an Arc) or expensive (a large Vec). Java: clone() or a copy constructor, but in Rust you see every copy in the code.

Closure

An anonymous function that can capture variables: |o| o.total_cents > min. Java: a lambda, but a Rust closure can also change captured variables.

Copy

A marker trait for small types that copy bit by bit on assignment, instead of moving: integers, bool, char, and structs that derive it. Java: primitive types.

Crate

The unit of compilation: a library or a binary. Published crates live on crates.io. Java: a JAR; C#: an assembly.

Derive

#[derive(Debug, Clone, PartialEq)]: an attribute that generates trait implementations. Java: what Lombok or your IDE generates (toString, equals, hashCode).

Enum, variant

A type that is one of several variants, and each variant can carry its own data. Java: a sealed interface with one record per case (more than a Java enum).

Expression

Code that produces a value. In Rust, if, match, and blocks are expressions. The last expression in a block, without ;, is the block’s value. Java: the ternary operator and switch expressions.

Lifetime

The span of code where a reference is valid. An annotation such as 'a names a lifetime so that the compiler can relate references; it does not change how long a value lives. Java: none.

Macro

Code that generates code at compile time. A call has a ! (println!, vec!); attributes such as #[derive] are macros too. Java: annotation processors; there is no direct equivalent to name!(...).

Match, pattern

match compares a value against patterns and runs the first arm that fits. It must cover every case. Patterns can destructure, bind names, and test ranges. Java: a switch expression with patterns.

Module

A namespace inside a crate: mod orders;. Privacy works at the module level, not the type level. Java: a package, roughly.

Move

Transfer of ownership. Assignment and passing a non-Copy value to a function move it, and the old name cannot be used after that. Java: none; Java copies the reference and both names stay valid.

Option

Option<T> is Some(value) or None. Rust has no null, so a missing value is always an Option. Java: Optional<T>, but used everywhere, including fields and parameters.

Ownership

The rule that every value has exactly one owner. When the owner goes out of scope, the value is dropped (freed). Java: none; the garbage collector frees objects. C#: like using/IDisposable for every value.

Panic

An unrecoverable error that unwinds the current thread (or aborts the process). unwrap(), expect(), panic!, and out-of-range indexing panic. Java: an Error or an uncaught RuntimeException; not for normal control flow.

Question mark operator (?)

After an expression of type Result or Option: return the error (or None) to the caller now, or continue with the value. Java: like letting a checked exception propagate, but visible on each line.

Result

Result<T, E> is Ok(value) or Err(error). Errors are values in the return type, not exceptions. Java: a checked exception in the throws clause.

Shadowing

Declaring a new variable with the same name as an earlier one: let total = total * 2;. The old one is hidden. Normal in Rust. Java: not allowed for local variables.

Slice

A borrowed view of part or all of a sequence: &[T] for a list, &str for a string. Java: List.subList or a CharSequence, but without copying and checked by the compiler.

Smell

On this site: a pattern that compiles but makes code worse. Each smell has a permanent ID (S01 to S38). See the smell catalogue.

String and &str

String is an owned, growable UTF-8 string. &str is a borrowed string slice, for example a literal or part of a String. Java: StringBuilder/String for String; a read-only CharSequence view for &str.

Struct, impl

A struct holds named fields. Methods are defined separately in an impl block. There is no inheritance. Java: a class without inheritance; a record when the fields are public and immutable.

Trait

A set of methods that types can implement, possibly with default implementations. Java: an interface with default methods. C#: an interface, plus the ability to implement it for types you did not write (like extension methods).

Trait bound

A requirement on a generic type: T: Display, or in a where clause. Java: <T extends Comparable<T>>.

Trait object (dyn Trait)

A value of some type that implements a trait, known only at run time, called through a vtable. Usually behind a pointer: Box<dyn Trait>, &dyn Trait. Java: every interface-typed variable.

Turbofish (::<>)

A generic type argument given at the call site: text.parse::<u32>(). Java: Collections.<String>emptyList().

Unwrap

unwrap() takes the value out of an Option or Result and panics if there is none. expect("msg") does the same with a message. Java: Optional.get() or orElseThrow().

Vec

Vec<T>, the growable list type. Java: ArrayList<T>.