Skip to content

Commit edbaabc

Browse files
committed
enable cloning of some introspection structs
thanks to @t4ccer on github for prompting this and providing an initial partial implementation in MR 64 that I didn't end up using. closes #44.
1 parent 2881836 commit edbaabc

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed

pulse-binding/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# <unreleased>
2+
3+
* Added `to_owned()` methods to a bunch of objects like `SinkInfo` (as requested back in 2021 in
4+
issue 44). Thanks to @t4ccer on github for prompting this and providing an initial partial
5+
implementation.
6+
17
# 2.29.0 (March 3rd, 2025)
28

39
* Bumped MSRV from 1.56 to 1.63 per libc dependency.

pulse-binding/src/context/ext_device_manager.rs

+19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ impl<'a> RolePriorityInfo<'a> {
4747
}
4848
}
4949
}
50+
51+
/// Creates a copy with owned data.
52+
pub fn to_owned(&self) -> RolePriorityInfo<'static> {
53+
RolePriorityInfo {
54+
role: self.role.clone().map(|o| Cow::Owned(o.into_owned())),
55+
..*self
56+
}
57+
}
5058
}
5159

5260
/// Stores information about one device in the device database that is maintained by
@@ -102,6 +110,17 @@ impl<'a> Info<'a> {
102110
}
103111
}
104112
}
113+
114+
/// Creates a copy with owned data.
115+
pub fn to_owned(&self) -> Info<'static> {
116+
Info {
117+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
118+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
119+
icon: self.icon.clone().map(|o| Cow::Owned(o.into_owned())),
120+
role_priorities: self.role_priorities.iter().map(RolePriorityInfo::to_owned).collect(),
121+
..*self
122+
}
123+
}
105124
}
106125

107126
/// A wrapper object providing device manager routines to a context.

pulse-binding/src/context/ext_device_restore.rs

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ impl Info {
5252

5353
Info { dtype: src.dtype, index: src.index, formats: formats_vec }
5454
}
55+
56+
/// Creates a copy with owned data.
57+
pub fn to_owned(&self) -> Info {
58+
Info {
59+
formats: self.formats.clone(), //Our implementation makes an owned copy!
60+
..*self
61+
}
62+
}
5563
}
5664

5765
/// A wrapper object providing device restore routines to a context.

pulse-binding/src/context/ext_stream_restore.rs

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ impl<'a> Info<'a> {
6464
}
6565
}
6666
}
67+
68+
/// Creates a copy with owned data.
69+
pub fn to_owned(&self) -> Info<'static> {
70+
Info {
71+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
72+
device: self.device.clone().map(|o| Cow::Owned(o.into_owned())),
73+
..*self
74+
}
75+
}
6776
}
6877

6978
/// A wrapper object providing stream restore routines to a context.

pulse-binding/src/context/introspect.rs

+154
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ impl<'a> SinkPortInfo<'a> {
324324
}
325325
}
326326
}
327+
328+
/// Creates a copy with owned 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+
#[cfg(any(doc, feature = "pa_v14"))]
334+
availability_group: self.availability_group.clone().map(|o| Cow::Owned(o.into_owned())),
335+
..*self
336+
}
337+
}
327338
}
328339

329340
/// Stores information about sinks.
@@ -452,6 +463,21 @@ impl<'a> SinkInfo<'a> {
452463
}
453464
}
454465
}
466+
467+
/// Creates a copy with owned data.
468+
pub fn to_owned(&self) -> SinkInfo<'static> {
469+
SinkInfo {
470+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
471+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
472+
monitor_source_name: self.monitor_source_name.clone().map(|o| Cow::Owned(o.into_owned())),
473+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
474+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
475+
ports: self.ports.iter().map(SinkPortInfo::to_owned).collect(),
476+
active_port: self.active_port.as_ref().map(|ap| Box::new(ap.as_ref().to_owned())),
477+
formats: self.formats.clone(), //Our implementation makes an owned copy!
478+
..*self
479+
}
480+
}
455481
}
456482

457483
impl Introspector {
@@ -725,6 +751,17 @@ impl<'a> SourcePortInfo<'a> {
725751
}
726752
}
727753
}
754+
755+
/// Creates a copy with owned data.
756+
pub fn to_owned(&self) -> SourcePortInfo<'static> {
757+
SourcePortInfo {
758+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
759+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
760+
#[cfg(any(doc, feature = "pa_v14"))]
761+
availability_group: self.availability_group.clone().map(|o| Cow::Owned(o.into_owned())),
762+
..*self
763+
}
764+
}
728765
}
729766

730767
/// Stores information about sources.
@@ -856,6 +893,21 @@ impl<'a> SourceInfo<'a> {
856893
}
857894
}
858895
}
896+
897+
/// Creates a copy with owned data.
898+
pub fn to_owned(&self) -> SourceInfo<'static> {
899+
SourceInfo {
900+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
901+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
902+
monitor_of_sink_name: self.monitor_of_sink_name.clone().map(|o| Cow::Owned(o.into_owned())),
903+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
904+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
905+
ports: self.ports.iter().map(SourcePortInfo::to_owned).collect(),
906+
active_port: self.active_port.as_ref().map(|ap| Box::new(ap.as_ref().to_owned())),
907+
formats: self.formats.clone(), //Our implementation makes an owned copy!
908+
..*self
909+
}
910+
}
859911
}
860912

861913
impl Introspector {
@@ -1123,6 +1175,19 @@ impl<'a> ServerInfo<'a> {
11231175
}
11241176
}
11251177
}
1178+
1179+
/// Creates a copy with owned data.
1180+
pub fn to_owned(&self) -> ServerInfo<'static> {
1181+
ServerInfo {
1182+
user_name: self.user_name.clone().map(|o| Cow::Owned(o.into_owned())),
1183+
host_name: self.host_name.clone().map(|o| Cow::Owned(o.into_owned())),
1184+
server_version: self.server_version.clone().map(|o| Cow::Owned(o.into_owned())),
1185+
server_name: self.server_name.clone().map(|o| Cow::Owned(o.into_owned())),
1186+
default_sink_name: self.default_sink_name.clone().map(|o| Cow::Owned(o.into_owned())),
1187+
default_source_name: self.default_source_name.clone().map(|o| Cow::Owned(o.into_owned())),
1188+
..*self
1189+
}
1190+
}
11261191
}
11271192

11281193
impl Introspector {
@@ -1200,6 +1265,16 @@ impl<'a> ModuleInfo<'a> {
12001265
}
12011266
}
12021267
}
1268+
1269+
/// Creates a copy with owned data.
1270+
pub fn to_owned(&self) -> ModuleInfo<'static> {
1271+
ModuleInfo {
1272+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
1273+
argument: self.argument.clone().map(|o| Cow::Owned(o.into_owned())),
1274+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
1275+
..*self
1276+
}
1277+
}
12031278
}
12041279

12051280
impl Introspector {
@@ -1392,6 +1467,16 @@ impl<'a> ClientInfo<'a> {
13921467
}
13931468
}
13941469
}
1470+
1471+
/// Creates a copy with owned data.
1472+
pub fn to_owned(&self) -> ClientInfo<'static> {
1473+
ClientInfo {
1474+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
1475+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
1476+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
1477+
..*self
1478+
}
1479+
}
13951480
}
13961481

13971482
impl Introspector {
@@ -1503,6 +1588,15 @@ impl<'a> CardProfileInfo<'a> {
15031588
}
15041589
}
15051590
}
1591+
1592+
/// Creates a copy with owned data.
1593+
pub fn to_owned(&self) -> CardProfileInfo<'static> {
1594+
CardProfileInfo {
1595+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
1596+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
1597+
..*self
1598+
}
1599+
}
15061600
}
15071601

15081602
/// Stores information about a specific port of a card.
@@ -1596,6 +1690,19 @@ impl<'a> CardPortInfo<'a> {
15961690
}
15971691
}
15981692
}
1693+
1694+
/// Creates a copy with owned data.
1695+
pub fn to_owned(&self) -> CardPortInfo<'static> {
1696+
CardPortInfo {
1697+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
1698+
description: self.description.clone().map(|o| Cow::Owned(o.into_owned())),
1699+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
1700+
profiles: self.profiles.iter().map(CardProfileInfo::to_owned).collect(),
1701+
#[cfg(any(doc, feature = "pa_v14"))]
1702+
availability_group: self.availability_group.clone().map(|o| Cow::Owned(o.into_owned())),
1703+
..*self
1704+
}
1705+
}
15991706
}
16001707

16011708
/// Stores information about cards.
@@ -1671,6 +1778,19 @@ impl<'a> CardInfo<'a> {
16711778
}
16721779
}
16731780
}
1781+
1782+
/// Creates a copy with owned data.
1783+
pub fn to_owned(&self) -> CardInfo<'static> {
1784+
CardInfo {
1785+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
1786+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
1787+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
1788+
ports: self.ports.iter().map(CardPortInfo::to_owned).collect(),
1789+
profiles: self.profiles.iter().map(CardProfileInfo::to_owned).collect(),
1790+
active_profile: self.active_profile.as_ref().map(|ap| Box::new(ap.as_ref().to_owned())),
1791+
..*self
1792+
}
1793+
}
16741794
}
16751795

16761796
impl Introspector {
@@ -1895,6 +2015,18 @@ impl<'a> SinkInputInfo<'a> {
18952015
}
18962016
}
18972017
}
2018+
2019+
/// Creates a copy with owned data.
2020+
pub fn to_owned(&self) -> SinkInputInfo<'static> {
2021+
SinkInputInfo {
2022+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
2023+
resample_method: self.resample_method.clone().map(|o| Cow::Owned(o.into_owned())),
2024+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
2025+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
2026+
format: self.format.clone(), //Our implementation makes an owned copy!
2027+
..*self
2028+
}
2029+
}
18982030
}
18992031

19002032
impl Introspector {
@@ -2124,6 +2256,18 @@ impl<'a> SourceOutputInfo<'a> {
21242256
}
21252257
}
21262258
}
2259+
2260+
/// Creates a copy with owned data.
2261+
pub fn to_owned(&self) -> SourceOutputInfo<'static> {
2262+
SourceOutputInfo {
2263+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
2264+
resample_method: self.resample_method.clone().map(|o| Cow::Owned(o.into_owned())),
2265+
driver: self.driver.clone().map(|o| Cow::Owned(o.into_owned())),
2266+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
2267+
format: self.format.clone(), //Our implementation makes an owned copy!
2268+
..*self
2269+
}
2270+
}
21272271
}
21282272

21292273
impl Introspector {
@@ -2337,6 +2481,16 @@ impl<'a> SampleInfo<'a> {
23372481
}
23382482
}
23392483
}
2484+
2485+
/// Creates a copy with owned data.
2486+
pub fn to_owned(&self) -> SampleInfo<'static> {
2487+
SampleInfo {
2488+
name: self.name.clone().map(|o| Cow::Owned(o.into_owned())),
2489+
filename: self.filename.clone().map(|o| Cow::Owned(o.into_owned())),
2490+
proplist: self.proplist.clone(), //Our implementation makes an owned copy!
2491+
..*self
2492+
}
2493+
}
23402494
}
23412495

23422496
impl Introspector {

0 commit comments

Comments
 (0)