pulse-binding-rust icon indicating copy to clipboard operation
pulse-binding-rust copied to clipboard

Derive Clone for SinkInfo and SinkPortInfo

Open agraven opened this issue 3 years ago • 3 comments

The Clone implementation enables using data from a SinkInfo outside the callback functions where a reference to one is made available

agraven avatar Sep 24 '21 16:09 agraven

Hm, because of how Clone is implemented for Cow this would have to do Cow::Owned(field.clone().into_owned()) on every field with a Cow to work the way I had in mind.

agraven avatar Sep 24 '21 19:09 agraven

I've also noticed that the API lacks something like this.

I guess changing it into an owned value doesn't really have the expected semantics of a Clone, to_owned means something a bit different, and into_owned would be expected to take self...

Maybe derive Clone, but also have an into_owned(self) -> Self<'static> method to match Cow? Looks like something like https://crates.io/crates/derive-into-owned could derive that automatically.

ids1024 avatar Jun 13 '22 20:06 ids1024

Or... I see you already mentioned that same crate on https://github.com/jnqnfe/pulse-binding-rust/issues/44.

There is a bit of complexity in SinkInfo since it has Option<Cow<_>> fields and a Vec<SinkPortInfo<'a>> field where SinkPortInfo also contains Cow types. It may require a custom macro (or maybe improvements could be made to derive-into-owned)?

ids1024 avatar Jun 13 '22 21:06 ids1024