Skip to content

Commit e367599

Browse files
committed
introspect: add to_owned functions to SinkInfo and SinkPortInfo
1 parent c4dcf6b commit e367599

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

pulse-binding/src/context/introspect.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl Drop for Introspector {
258258
///
259259
/// Please note that this structure can be extended as part of evolutionary API updates at any time
260260
/// in any new release.
261-
#[derive(Debug)]
261+
#[derive(Debug, Clone)]
262262
pub struct SinkPortInfo<'a> {
263263
/// Name of this port.
264264
pub name: Option<Cow<'a, str>>,
@@ -324,13 +324,23 @@ impl<'a> SinkPortInfo<'a> {
324324
}
325325
}
326326
}
327+
328+
/// Creates owned data from borrowed data
329+
pub fn to_owned(&self) -> SinkPortInfo<'static> {
330+
SinkPortInfo {
331+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
332+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
333+
availability_group: self.availability_group.clone().map(|o| Cow::Owned(o.into_owned())),
334+
..*self
335+
}
336+
}
327337
}
328338

329339
/// Stores information about sinks.
330340
///
331341
/// Please note that this structure can be extended as part of evolutionary API updates at any time
332342
/// in any new release.
333-
#[derive(Debug)]
343+
#[derive(Debug, Clone)]
334344
pub struct SinkInfo<'a> {
335345
/// Name of the sink.
336346
pub name: Option<Cow<'a, str>>,
@@ -452,6 +462,27 @@ impl<'a> SinkInfo<'a> {
452462
}
453463
}
454464
}
465+
466+
/// Creates owned data from borrowed data
467+
pub fn to_owned(&self) -> SinkInfo<'static> {
468+
SinkInfo {
469+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
470+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
471+
monitor_source_name: self
472+
.monitor_source_name
473+
.clone()
474+
.map(|o| Cow::Owned(o.into_owned())),
475+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
476+
proplist: self.proplist.clone(),
477+
ports: self.ports.iter().map(SinkPortInfo::to_owned).collect(),
478+
active_port: self
479+
.active_port
480+
.as_ref()
481+
.map(|spi| Box::new(spi.as_ref().to_owned())),
482+
formats: self.formats.clone(),
483+
..*self
484+
}
485+
}
455486
}
456487

457488
impl Introspector {

pulse-binding/src/def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl AsRef<capi::pa_spawn_api> for SpawnApi {
299299

300300
bitflags! {
301301
/// Set of sink flags.
302-
#[derive(Debug)]
302+
#[derive(Debug, Clone, Copy)]
303303
#[repr(transparent)]
304304
pub struct SinkFlagSet: u32 {
305305
/// Flag to pass when no specific options are needed.

0 commit comments

Comments
 (0)