Skip to main content

Traits for Rusts

Traits in Rust define shared behaviour that different types can implement, and generics let code work over many types with trait bounds. Together they provide static polymorphism with no runtime cost. Closures and iterators build on traits like Fn and Iterator to give expressive, lazy data processing.

Stage: Abstraction · Part of the Rust roadmap · Last reviewed 19 November 2026

What to learn in Traits

Traits interview questions

What is the difference between generics and trait objects?

Generics are resolved at compile time through monomorphisation, giving fast code but one copy per type. Trait objects, written dyn Trait, use dynamic dispatch through a vtable, allowing mixed types in one collection at a small runtime cost.

Are Rust iterators lazy?

Yes. Adapters like map and filter do nothing until a consumer, such as collect, sum or a for loop, drives them. This lets chains run in one pass without building intermediate collections, and the optimiser often turns them into code as fast as a manual loop.

Where Traits fits in the Rust roadmap

Traits belongs to the Abstraction stage (advanced level), which takes about 28 hours. Traits and errors.

Back to the full Rust roadmap