swiftide
swiftide copied to clipboard
Public api clone cleanup
Is your feature request related to a problem? Please describe. Currently pipeline steps and prompting/embedding clients require owned arguments. In examples and in production code this leads to a lot of clones. Although this is performance wise fine because of the magic of Arc, it does make for a verbose and less ideomatic api.
Describe the solution you'd like Ideally, both owned and borrowed are accepted for all steps. Additionally, trait objects should also be supported. Internally it can then make an owned copy.
For example:
let transformer = MyTransformer::new();
pipeline.then(transformer)
pipeline.then(&transformer)
let transformer: Box<dyn Transformer> = MyTransformer::new();
pipeline.then(transformer)
pipeline.then(transformer.clone())
pipeline.then(&transformer)
Should all work. With concrete objects this is typically achieved with AsRef, Borrow or Into. The problem AsRef works, but would require an implementation for all concrete types. Borrow has a blanket implimentation, I haven't been able to get it to work yet.
dyn-clone should help here as well. I've played around a bit with the puzzle at https://github.com/timonv/traitobjects-dynclone.
Additionally, this should not introduce breaking changes, nor introduce lifetimes all over the place (at least not in the public api).