← All notes

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

Claims

Sources

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

Permanent ID: iil:note:anys37hh

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.},
}

Markdown

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.