4 ms·
> The biggest annoying magic I found with respect to Box (and other std containers like Rc) is that they’re the only ones capable of storing fat dyn pointers.
by gpm 3y ago
> The biggest annoying magic I found with respect to Box (and other std containers like Rc) is that they’re the only ones capable of storing fat dyn pointers. You can’t construct a hybrid_rc::Rc<dyn Trait> like you can with Box/Rc.
Anything can store fat dyn pointers, they're just like any other type in that regards.
Constructing them for a specific trait is easy and possible on stable (e.g. adding a `as_debug(MyBox<T>) -> MyBox<dyn Debug>` method).
Making it possible to construct them for any trait is special to the built in pointers... on stable. On nightly with unstable features it's possible (and easy) to make any smart pointer type do this.
Code examples:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=666ddb5abc3902867ac179c148cb22d4 https://play.rust-lang.org/?version=nightly&mode=debug&editi...
- vlovich123 3y agoI should have taken more time on that and miswrote. Converting MyBox<T> to MyBox<dyn Trait> for arbitrary traits is only possible on nightly.