Rust traits and trait bounds
Short answer
A trait defines shared behavior as a set of method signatures, similar to interfaces elsewhere. Types implement traits with impl Trait for Type, and generics use trait bounds (T: Display) to accept any type with that behavior. Generic code is monomorphized at compile time, so it is as fast as concrete code. [S1][S2]
trait Summary { fn summarize(&self) -> String { "(more)".into() } }
fn notify(item: &impl Summary) { println!("{}", item.summarize()); }
Key points
- Traits can provide default method implementations. [S1]
- The orphan rule: you can implement a trait for a type only if the trait or the type is local to your crate. [S1]
Claims
- id: C1 claim: A trait defines functionality a type has and can share. source: S1 evidence: "A trait defines the functionality a particular type has and can share with"
- id: C2 claim: Traits are similar to interfaces in other languages. source: S1 evidence: "Traits are similar to a feature often called interfaces in other"
- id: C3 claim: Rust performs monomorphization of generic code at compile time. source: S2 evidence: "Rust accomplishes this by performing monomorphization of the code using"
- id: C4 claim: Generics in signatures prevent code duplication. source: S2 evidence: "more functionality to callers of our function while preventing code duplication."
Sources
- [S1] Defining Shared Behavior with Traits - The Rust Programming Language. The Rust Project (The Rust Programming Language book). https://doc.rust-lang.org/book/ch10-02-traits.html . License: MIT OR Apache-2.0 (rust-lang/book). Accessed 2026-11-04.
- [S2] Generic Data Types - The Rust Programming Language. The Rust Project (The Rust Programming Language book). https://doc.rust-lang.org/book/ch10-01-syntax.html . License: MIT OR Apache-2.0 (rust-lang/book). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Copyright (c) 2010 The Rust Project Developers. Sources: The Rust Project (The Rust Programming Language book), Defining Shared Behavior with Traits - The Rust Programming Language, MIT OR Apache-2.0 (rust-lang/book); The Rust Project (The Rust Programming Language book), Generic Data Types - The Rust Programming Language, MIT OR Apache-2.0 (rust-lang/book).
Cite this
iinventedlight. 2026. "Rust traits and trait bounds." iinventedlight Library, iil:note:anys37hh, version of 2026-11-04. https://iinventedlight.com/library/notes/rust-traits/. License: CC-BY-4.0.
@misc{iil_note_anys37hh,
author = {{iinventedlight}},
title = {{Rust traits and trait bounds}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/rust-traits/},
note = {Permanent ID iil:note:anys37hh. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/rust-traits.md.