libobs_simple\sources/
either.rs1use libobs_wrapper::{
2 data::{object::ObsObjectTrait, ImmutableObsData, ObsData},
3 sources::{ObsFilterGuardPair, ObsFilterRef, ObsSourceSignals, ObsSourceTrait},
4 unsafe_send::SmartPointerSendable,
5 utils::ObsError,
6};
7
8#[derive(Debug, Clone)]
9pub enum ObsEitherSource<A: ObsSourceTrait + Clone + 'static, B: ObsSourceTrait + Clone + 'static> {
10 Left(A),
11 Right(B),
12}
13
14impl<A, B> libobs_wrapper::data::object::ObsObjectTraitPrivate for ObsEitherSource<A, B>
15where
16 A: ObsSourceTrait + Clone + 'static,
17 B: ObsSourceTrait + Clone + 'static,
18{
19 fn __internal_replace_settings(
20 &self,
21 settings: libobs_wrapper::data::ImmutableObsData,
22 ) -> Result<(), ObsError> {
23 match self {
24 ObsEitherSource::Left(a) => a.__internal_replace_settings(settings),
25 ObsEitherSource::Right(b) => b.__internal_replace_settings(settings),
26 }
27 }
28
29 fn __internal_replace_hotkey_data(
30 &self,
31 hotkey_data: libobs_wrapper::data::ImmutableObsData,
32 ) -> Result<(), ObsError> {
33 match self {
34 ObsEitherSource::Left(a) => a.__internal_replace_hotkey_data(hotkey_data),
35 ObsEitherSource::Right(b) => b.__internal_replace_hotkey_data(hotkey_data),
36 }
37 }
38}
39
40impl<A, B> ObsObjectTrait for ObsEitherSource<A, B>
41where
42 A: ObsSourceTrait + Clone + 'static,
43 B: ObsSourceTrait + Clone + 'static,
44{
45 type Native = *mut libobs::obs_source;
46
47 fn __native_handle(&self) -> SmartPointerSendable<Self::Native> {
48 match self {
49 ObsEitherSource::Left(a) => a.__native_handle(),
50 ObsEitherSource::Right(b) => b.__native_handle(),
51 }
52 }
53
54 fn runtime(&self) -> &libobs_wrapper::runtime::ObsRuntime {
55 match self {
56 ObsEitherSource::Left(a) => a.runtime(),
57 ObsEitherSource::Right(b) => b.runtime(),
58 }
59 }
60
61 fn settings(&self) -> Result<ImmutableObsData, ObsError> {
62 match self {
63 ObsEitherSource::Left(a) => a.settings(),
64 ObsEitherSource::Right(b) => b.settings(),
65 }
66 }
67
68 fn hotkey_data(&self) -> Result<ImmutableObsData, ObsError> {
69 match self {
70 ObsEitherSource::Left(a) => a.hotkey_data(),
71 ObsEitherSource::Right(b) => b.hotkey_data(),
72 }
73 }
74
75 fn id(&self) -> libobs_wrapper::utils::ObsString {
76 match self {
77 ObsEitherSource::Left(a) => a.id(),
78 ObsEitherSource::Right(b) => b.id(),
79 }
80 }
81
82 fn name(&self) -> libobs_wrapper::utils::ObsString {
83 match self {
84 ObsEitherSource::Left(a) => a.name(),
85 ObsEitherSource::Right(b) => b.name(),
86 }
87 }
88
89 fn update_settings(&self, settings: ObsData) -> Result<(), ObsError> {
90 match self {
91 ObsEitherSource::Left(a) => a.update_settings(settings),
92 ObsEitherSource::Right(b) => b.update_settings(settings),
93 }
94 }
95}
96
97impl<A, B> ObsSourceTrait for ObsEitherSource<A, B>
98where
99 A: ObsSourceTrait + Clone + 'static,
100 B: ObsSourceTrait + Clone + 'static,
101{
102 fn signals(&self) -> &std::sync::Arc<ObsSourceSignals> {
103 match self {
104 ObsEitherSource::Left(a) => a.signals(),
105 ObsEitherSource::Right(b) => b.signals(),
106 }
107 }
108
109 fn get_active_filters(&self) -> Result<Vec<ObsFilterGuardPair>, ObsError> {
110 match self {
111 ObsEitherSource::Left(a) => a.get_active_filters(),
112 ObsEitherSource::Right(b) => b.get_active_filters(),
113 }
114 }
115
116 fn apply_filter(&self, filter: &ObsFilterRef) -> Result<(), ObsError> {
117 match self {
118 ObsEitherSource::Left(a) => a.apply_filter(filter),
119 ObsEitherSource::Right(b) => b.apply_filter(filter),
120 }
121 }
122}
123
124pub enum ObsEither<A, B> {
125 Left(A),
126 Right(B),
127}