Please see this example on the playground:
Specifically, the comments in
It gets even more hairy in my real-world use case where I want to match on a user-supplied string and return any number of structs that implement a specific Trait. There’s potential failure along the way and unwrapping a Result in order to re-wrap it is not ideal.
My workaround at the moment is different than here - rather I’ve just made the struct’s
new() return a
Result<Box<dyn Trait>, Error> - but that’s not wonderful.
Any insight and/or advice is appreciated. Thanks!