← All notes

impl Trait: concise trait bounds in arguments and returns

Answer: Write impl Trait on a function argument or return type when you only care that the type implements a trait. The book calls this syntax sugar for a longer trait bound.

In the Rust book

The impl Trait syntax is how you accept some type that implements a trait without spelling a generic parameter.

For straightforward cases it is convenient, and it is actually syntax sugar for the longer trait bound form.

The same syntax works in the return position when you want to return a value of some type that implements a trait.

Two positions in Rust by Example

Rust by Example lists two locations: argument type, and return type.

If the function is generic over a trait and you do not need to name the concrete type, impl Trait can be the type of the argument.

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, Defining Shared Behavior with Traits; Rust by Example, impl Trait. 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, Defining Shared Behavior with Traits; Rust by Example, impl Trait. 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:4scv9wya

iinventedlight. 2026. "impl Trait: concise trait bounds in arguments and returns." iinventedlight Library, iil:note:4scv9wya, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-impl-trait/. License: CC-BY-4.0.

@misc{iil_note_4scv9wya,
  author = {{iinventedlight}},
  title = {{impl Trait: concise trait bounds in arguments and returns}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/rust-impl-trait/},
  note = {Permanent ID iil:note:4scv9wya. 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-impl-trait.md.