libobs_wrapper\data\object/
mod.rs1use std::fmt::Debug;
2
3use crate::{
4 data::{ImmutableObsData, ObsData, ObsObjectUpdater},
5 macros::trait_with_optional_send_sync,
6 runtime::ObsRuntime,
7 unsafe_send::SmartPointerSendable,
8 utils::{ObsError, ObsString},
9};
10
11mod macros;
12pub(crate) use macros::*;
13
14pub trait ObsObjectClone<K: Clone> {
16 fn clone_box(&self) -> Box<dyn ObsObjectTrait<K>>;
17}
18
19impl<T, K: Clone> ObsObjectClone<K> for T
20where
21 T: ObsObjectTrait<K> + Clone + 'static,
22{
23 fn clone_box(&self) -> Box<dyn ObsObjectTrait<K>> {
24 Box::new(self.clone())
25 }
26}
27
28impl<K: Clone> Clone for Box<dyn ObsObjectTrait<K>> {
29 fn clone(&self) -> Self {
30 self.clone_box()
31 }
32}
33
34trait_with_optional_send_sync! {
35 #[doc(hidden)]
36 pub trait ObsObjectTraitPrivate: Debug {
37 fn __internal_replace_settings(&self, settings: ImmutableObsData) -> Result<(), ObsError>;
41 fn __internal_replace_hotkey_data(&self, hotkey_data: ImmutableObsData)
45 -> Result<(), ObsError>;
46 }
47}
48
49#[allow(private_bounds)]
50pub trait ObsObjectTrait<K: Clone>: ObsObjectClone<K> + ObsObjectTraitPrivate {
53 fn runtime(&self) -> &ObsRuntime;
54 fn settings(&self) -> Result<ImmutableObsData, ObsError>;
55 fn hotkey_data(&self) -> Result<ImmutableObsData, ObsError>;
56
57 fn id(&self) -> ObsString;
58 fn name(&self) -> ObsString;
59
60 fn update_settings(&self, settings: ObsData) -> Result<(), ObsError>;
62
63 fn create_updater<'a, T: ObsObjectUpdater<'a, K, ToUpdate = Self> + Send + Sync>(
66 &'a mut self,
67 ) -> Result<T, ObsError>
68 where
69 Self: Sized + Send + Sync,
70 {
71 let runtime = self.runtime().clone();
72 T::create_update(runtime, self)
73 }
74
75 fn as_ptr(&self) -> SmartPointerSendable<K>;
78}