From d8bbde345e33d00478326ffec60834685f79be2b Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Sat, 12 Apr 2025 21:45:18 +0100 Subject: [PATCH 1/2] enable cloning of some introspection structs other structs have problematic attributes of types like Proplist which will require more work. --- pulse-binding/src/context/introspect.rs | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pulse-binding/src/context/introspect.rs b/pulse-binding/src/context/introspect.rs index 9fd682d..3b4f8d7 100644 --- a/pulse-binding/src/context/introspect.rs +++ b/pulse-binding/src/context/introspect.rs @@ -324,6 +324,17 @@ impl<'a> SinkPortInfo<'a> { } } } + + /// Creates a copy with owned data. + pub fn to_owned(&self) -> SinkPortInfo<'static> { + SinkPortInfo { + name: self.name.clone().map(|o| Cow::Owned(o.into_owned())), + description: self.description.clone().map(|o| Cow::Owned(o.into_owned())), + #[cfg(any(doc, feature = "pa_v14"))] + availability_group: self.availability_group.clone().map(|o| Cow::Owned(o.into_owned())), + ..*self + } + } } /// Stores information about sinks. @@ -725,6 +736,17 @@ impl<'a> SourcePortInfo<'a> { } } } + + /// Creates a copy with owned data. + pub fn to_owned(&self) -> SourcePortInfo<'static> { + SourcePortInfo { + name: self.name.clone().map(|o| Cow::Owned(o.into_owned())), + description: self.description.clone().map(|o| Cow::Owned(o.into_owned())), + #[cfg(any(doc, feature = "pa_v14"))] + availability_group: self.availability_group.clone().map(|o| Cow::Owned(o.into_owned())), + ..*self + } + } } /// Stores information about sources. @@ -1123,6 +1145,19 @@ impl<'a> ServerInfo<'a> { } } } + + /// Creates a copy with owned data. + pub fn to_owned(&self) -> ServerInfo<'static> { + ServerInfo { + user_name: self.user_name.clone().map(|o| Cow::Owned(o.into_owned())), + host_name: self.host_name.clone().map(|o| Cow::Owned(o.into_owned())), + server_version: self.server_version.clone().map(|o| Cow::Owned(o.into_owned())), + server_name: self.server_name.clone().map(|o| Cow::Owned(o.into_owned())), + default_sink_name: self.default_sink_name.clone().map(|o| Cow::Owned(o.into_owned())), + default_source_name: self.default_source_name.clone().map(|o| Cow::Owned(o.into_owned())), + ..*self + } + } } impl Introspector { @@ -1503,6 +1538,15 @@ impl<'a> CardProfileInfo<'a> { } } } + + /// Creates a copy with owned data. + pub fn to_owned(&self) -> CardProfileInfo<'static> { + CardProfileInfo { + name: self.name.clone().map(|o| Cow::Owned(o.into_owned())), + description: self.description.clone().map(|o| Cow::Owned(o.into_owned())), + ..*self + } + } } /// Stores information about a specific port of a card. From 85d091434ca0e976d1101b1f514cfecd7cb90cc3 Mon Sep 17 00:00:00 2001 From: t4ccer Date: Sat, 12 Apr 2025 09:01:09 -0600 Subject: [PATCH 2/2] introspect: add `to_owned` functions to `SinkInfo` --- pulse-binding/src/context/introspect.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pulse-binding/src/context/introspect.rs b/pulse-binding/src/context/introspect.rs index 3b4f8d7..e52c6b4 100644 --- a/pulse-binding/src/context/introspect.rs +++ b/pulse-binding/src/context/introspect.rs @@ -463,6 +463,27 @@ impl<'a> SinkInfo<'a> { } } } + + /// Creates owned data from borrowed data + pub fn to_owned(&self) -> SinkInfo<'static> { + SinkInfo { + name: self.name.clone().map(|o| Cow::Owned(o.into_owned())), + description: self.description.clone().map(|o| Cow::Owned(o.into_owned())), + monitor_source_name: self + .monitor_source_name + .clone() + .map(|o| Cow::Owned(o.into_owned())), + driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())), + proplist: self.proplist.clone(), + ports: self.ports.iter().map(SinkPortInfo::to_owned).collect(), + active_port: self + .active_port + .as_ref() + .map(|spi| Box::new(spi.as_ref().to_owned())), + formats: self.formats.clone(), + ..*self + } + } } impl Introspector {