
Trait Objects in Rust and Why Some Traits Cannot Be One
A trait object is a pointer plus a vtable, which lets one Vec hold many types. See how to build one, what the cost is, and why some traits cannot be used this way.
Everything you need to level up your coding skills.

A trait object is a pointer plus a vtable, which lets one Vec hold many types. See how to build one, what the cost is, and why some traits cannot be used this way.

Trait bounds say what a generic type must be able to do. Learn the T: Trait syntax, where clauses, multiple bounds and when each form reads better.

A trait is a named set of methods a type promises to provide. See how to define one, implement it, give it default methods and use it as a bound.

Closures capture their environment, and the Fn, FnMut and FnOnce traits describe how. See which one the compiler picks and which bound to write.

Rust enums carry data in each variant, which replaces the class hierarchy and the nullable field. See the syntax, match, methods, and where it beats inheritance.

A guide to choosing between generics, impl Trait, trait objects and enums in Rust, with one example solved four ways and the costs of each.
We send one email when a new post is published. No spam.