4 ms·
> The main difficulty is we also have to understand the purpose of the dyn keyword and why the Error must be boxed. Box<dyn Trait> is just an owning opaque poi
by 0815test 7y ago
> The main difficulty is we also have to understand the purpose of the dyn keyword and why the Error must be boxed.
Box<dyn Trait> is just an owning opaque pointer to something that implements the Trait interface. This kind of stuff is done all the time in C/C++ because it's just so darn useful, even though it requires a bunch of boilerplate code to make it work properly. (It's also arguably implied in the semantics of other languages, even though it's not directly marked in the code.) In Rust, it's just a line of code and the compiler provides checks that ensure you're writing something reasonable. (And of course you can dispense with the whole boxing mechanism when it's not needed, same as in C.)