What is the cited problem with using generic type parameters in trait objects?

what does it mean “generic type parameters that are filled in with concrete type parameters when the trait is used”

An example that won’t work is when the type parameter is part of a method:

trait Foo {
    fn foo<T>(t: T) {}
}

When a function has a type parameter, Rust will monomorphize the function (make a new copy) for each type that it is actually called with. This isn’t compatible with trait objects because Rust doesn’t know which impl the method belongs to until runtime.

Leave a Comment