546 B
546 B
Inline dyn
A relatively simple example wrapper working (kinda) as a by-value dyn Trait.
Limitations:
- The wrapper size is fixed. The content either fits, or it doesn’t compile.
- Supporting each trait requires a bit of code, as there is no way to express “for each trait X” in Rust.
- Like with
Box<dyn _>, you can’t call by-value methods on the content. - Requires unstable features (notably
ptr_metadata, others are probably avoidable). unsafehere,unsafethere,unsafeeverywhere! (It does pass Miri though).