diff --git a/pulse-binding/src/context/introspect.rs b/pulse-binding/src/context/introspect.rs index 9fd682d..e52c6b4 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. @@ -452,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 { @@ -725,6 +757,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 +1166,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 +1559,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.