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<*mut libobs::obs_source> for ObsEitherSource<A, B>
41where
42 A: ObsSourceTrait + Clone + 'static,
43 B: ObsSourceTrait + Clone + 'static,
44{
45 fn runtime(&self) -> &libobs_wrapper::runtime::ObsRuntime {
46 match self {
47 ObsEitherSource::Left(a) => a.runtime(),
48 ObsEitherSource::Right(b) => b.runtime(),
49 }
50 }
51
52 fn settings(&self) -> Result<ImmutableObsData, ObsError> {
53 match self {
54 ObsEitherSource::Left(a) => a.settings(),
55 ObsEitherSource::Right(b) => b.settings(),
56 }
57 }
58
59 fn hotkey_data(&self) -> Result<ImmutableObsData, ObsError> {
60 match self {
61 ObsEitherSource::Left(a) => a.hotkey_data(),
62 ObsEitherSource::Right(b) => b.hotkey_data(),
63 }
64 }
65
66 fn id(&self) -> libobs_wrapper::utils::ObsString {
67 match self {
68 ObsEitherSource::Left(a) => a.id(),
69 ObsEitherSource::Right(b) => b.id(),
70 }
71 }
72
73 fn name(&self) -> libobs_wrapper::utils::ObsString {
74 match self {
75 ObsEitherSource::Left(a) => a.name(),
76 ObsEitherSource::Right(b) => b.name(),
77 }
78 }
79
80 fn update_settings(&self, settings: ObsData) -> Result<(), ObsError> {
81 match self {
82 ObsEitherSource::Left(a) => a.update_settings(settings),
83 ObsEitherSource::Right(b) => b.update_settings(settings),
84 }
85 }
86
87 fn as_ptr(&self) -> SmartPointerSendable<*mut libobs::obs_source> {
88 match self {
89 ObsEitherSource::Left(a) => a.as_ptr(),
90 ObsEitherSource::Right(b) => b.as_ptr(),
91 }
92 }
93}
94
95impl<A, B> ObsSourceTrait for ObsEitherSource<A, B>
96where
97 A: ObsSourceTrait + Clone + 'static,
98 B: ObsSourceTrait + Clone + 'static,
99{
100 fn signals(&self) -> &std::sync::Arc<ObsSourceSignals> {
101 match self {
102 ObsEitherSource::Left(a) => a.signals(),
103 ObsEitherSource::Right(b) => b.signals(),
104 }
105 }
106
107 fn get_active_filters(&self) -> Result<Vec<ObsFilterGuardPair>, ObsError> {
108 match self {
109 ObsEitherSource::Left(a) => a.get_active_filters(),
110 ObsEitherSource::Right(b) => b.get_active_filters(),
111 }
112 }
113
114 fn apply_filter(&self, filter: &ObsFilterRef) -> Result<(), ObsError> {
115 match self {
116 ObsEitherSource::Left(a) => a.apply_filter(filter),
117 ObsEitherSource::Right(b) => b.apply_filter(filter),
118 }
119 }
120}
121
122pub enum ObsEither<A, B> {
123 Left(A),
124 Right(B),
125}