libobs_wrapper\data/
lib_support.rs

1//! Use the `libobs-source` crate to create sources like `window_capture` for obs
2
3use crate::{
4    data::{object::ObsObjectTrait, ObsData},
5    runtime::ObsRuntime,
6    utils::{ObjectInfo, ObsError, ObsString},
7};
8
9use super::updater::ObsDataUpdater;
10
11/// Should be implemented for any enum that can be represented as a String.
12///
13/// This is mostly used for `ObsSourceBuilders`.
14pub trait StringEnum {
15    fn to_str(&self) -> &str;
16}
17
18/// Trait for building OBS objects.
19/// This can range from building audio encoders to building scenes, every ObsObject
20/// has the same underlying properties:
21/// - name
22/// - id
23/// - hotkey_data
24/// - settings
25pub trait ObsObjectBuilder {
26    fn new<T: Into<ObsString> + Send + Sync>(
27        name: T,
28        runtime: ObsRuntime,
29    ) -> Result<Self, ObsError>
30    where
31        Self: Sized;
32
33    fn runtime(&self) -> &ObsRuntime;
34
35    /// Returns the name of the source.
36    fn get_name(&self) -> ObsString;
37
38    fn object_build(self) -> Result<ObjectInfo, ObsError>
39    where
40        Self: Sized;
41
42    fn get_settings(&self) -> &ObsData;
43    fn get_settings_updater(&mut self) -> &mut ObsDataUpdater;
44
45    fn get_hotkeys(&self) -> &ObsData;
46    fn get_hotkeys_updater(&mut self) -> &mut ObsDataUpdater;
47
48    /// Returns the ID of the source.
49    fn get_id() -> ObsString;
50}
51
52/// A trait that is used to represent any struct than can update an OBS object.
53/// This can be for example a ´WindowSourceUpdater´, which updates the settings of the `WindowSourceRef`, when
54/// the `update` method is called.
55pub trait ObsObjectUpdater<'a, K: Clone> {
56    type ToUpdate: ObsObjectTrait<K>;
57    fn create_update(
58        runtime: ObsRuntime,
59        updatable: &'a mut Self::ToUpdate,
60    ) -> Result<Self, ObsError>
61    where
62        Self: Sized;
63
64    fn get_settings(&self) -> &ObsData;
65    fn get_settings_updater(&mut self) -> &mut ObsDataUpdater;
66
67    fn update(self) -> Result<(), ObsError>;
68
69    fn runtime(&self) -> &ObsRuntime;
70
71    /// Returns the ID of the object
72    fn get_id() -> ObsString;
73}