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

Make SinkInfo, ServerInfo, and similar types available outside of callbacks

Open agraven opened this issue 3 years ago • 4 comments

The types listed in the title all share the issue that when you receive them in callbacks passed to methods like get_sink_info_by_name, you can't use those types outside of the callbacks due to lifetime constraints.

I first tried to address the issue by deriving Clone for the relevant structs, but I realized that won't solve the problem since cloning a Cow::Borrowed just produces a copy of the reference it contains. I next tried to see if the derive-into-owned crate would work, but the derive seems to fail on some types, for example SinkInfo.

agraven avatar Sep 24 '21 20:09 agraven

Sorry for the delay, I'll try to take a look at it all soon. I'm not ignoring you :)

jnqnfe avatar Oct 15 '21 05:10 jnqnfe

No worries, I've been quite busy myself as well :)

agraven avatar Oct 15 '21 06:10 agraven

Looking for the support of that as well :)

j4w3ny avatar Jan 28 '22 05:01 j4w3ny

I've just started extensively using this crate, and the ergonomics of the API are difficult around these borrowed structs. Since there's no public way to copy/clone them, we can only read them during the closures, and that makes it very difficult to consume...

For those curious, my workaround was to copy all of the structs, or create wrappers for some of them, and then inside the closures create instances of my struct copies. This isn't nice at all - if this crate changes anything then it'll break my structs, but it works for me for now.

I'm all for something like #43 - but instead of using a fork of this project with that addition (or just straight up duplicating the structs themselves), can we instead make some changes here? :pray:

acheronfail avatar Apr 26 '23 10:04 acheronfail