← All notes

Rust generics: one definition, many concrete types

Answer: Generics let you write one function or struct definition and then use it with many different concrete data types. The usual type parameter name is T, written in angle brackets.

Why the book introduces them

The book uses generics to create definitions for items such as function signatures or structs.

Those definitions can then be reused with many concrete types.

In a function, the generics go in the signature, where you would usually specify the data types of the parameters and the return value.

The result is more flexible code and less duplication.

Type parameters

Rust by Example treats generics as a way of generalizing types and functionalities to broader cases.

A type parameter is marked generic with angle brackets. <T> is the typical form.

Any type specified as a generic type parameter is generic. Everything else is concrete, or non-generic.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Generic Data Types; Rust by Example, Generics. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Generic Data Types; Rust by Example, Generics. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.

Cite this

Permanent ID: iil:note:vge2h66e

iinventedlight. 2026. "Rust generics: one definition, many concrete types." iinventedlight Library, iil:note:vge2h66e, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-generics/. License: CC-BY-4.0.

@misc{iil_note_vge2h66e,
  author = {{iinventedlight}},
  title = {{Rust generics: one definition, many concrete types}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/rust-generics/},
  note = {Permanent ID iil:note:vge2h66e. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-generics.md.