Yes, sorry, sometimes "type erasure" is used synonymously with dyn Trait
: Sectional introduction - Learning Rust
Rust's type-erasing
dyn Trait
offers ...
dyn Trait
of course does a lot more than just removing the need for a type parameter from the source code. It erases all type information, semantically. This is why you are required to downcast to get the concrete type back. That's a "neat trick" but it comes at a cost that is often too hard to pay.
I've had my fair share of debugging deeply nested types. (Looking at you, axum
.) My take here is that if you can read the docs, you can find your way through any typeck mess. It won't be fast, mind you, and it won't be easy. Then again, we don't get paid to do easy things, do we?
It would be awesome to have an extra tool that could analyze the error with great detail. But this is the realm of the trait resolver, which as I understand it, is kind of rough around the edges. (The next-gen trait solver has been underway since 2015.) I'm optimistic that errors could get better in the future. I am pessimistic on the outlook of dyn Trait
, though. The rules are too constraining and I don't know if it's possible to lift many of them.