jnqnfe / pulse-binding-rust

FFI and bindings for using PulseAudio from the Rust programming language.
Apache License 2.0
67 stars 20 forks source link

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

Open agraven opened 3 years ago

agraven commented 3 years ago

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.

jnqnfe commented 3 years ago

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

agraven commented 3 years ago

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

j4w3ny commented 2 years ago

Looking for the support of that as well :)

acheronfail commented 1 year ago

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: