4 ms·
Would it work to add a boxed_clone() function to your Material trait that returns a Box<Material>? (or create a BoxedClone trait if you need that pattern more g
by tangent128 9y ago
Would it work to add a boxed_clone() function to your Material trait that returns a Box<Material>? (or create a BoxedClone trait if you need that pattern more generally)
Implementations of boxed_clone() could still use &self.clone() to limit boilerplate.
Alternatively, if the Materials are not going to be modified and you just need multiple references to the same object, you could replace the Box<> with an Rc<> or Arc<>.
- comex 9y agoYep, those are the best approaches. For the former, you might consider the 'objekt' crate, which avoids the boilerplate: https://docs.rs/objekt/0.1.0/objekt/ https://docs.rs/objekt/0.1.0/objekt/