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::ObsData, runtime::ObsRuntime, utils::{traits::ObsUpdatable, ObjectInfo, ObsError, ObsString}
5};
6
7use super::updater::ObsDataUpdater;
8
9pub trait StringEnum {
10    fn to_str(&self) -> &str;
11}
12
13//TODO Use generics to make the build function return a trait rather than a struct
14/// Trait for building OBS sources.
15#[cfg_attr(not(feature="blocking"), async_trait::async_trait)]
16pub trait ObsObjectBuilder {
17    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
18    async fn new<T: Into<ObsString> + Send + Sync>(name: T, runtime: ObsRuntime) -> Result<Self, ObsError>
19    where
20        Self: Sized;
21
22    /// Returns the name of the source.
23    fn get_name(&self) -> ObsString;
24
25    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
26    async fn build(self) -> Result<ObjectInfo, ObsError>
27    where
28        Self: Sized;
29
30    fn get_settings(&self) -> &ObsData;
31    fn get_settings_updater(&mut self) -> &mut ObsDataUpdater;
32
33    fn get_hotkeys(&self) -> &ObsData;
34    fn get_hotkeys_updater(&mut self) -> &mut ObsDataUpdater;
35
36    /// Returns the ID of the source.
37    fn get_id() -> ObsString;
38}
39
40#[cfg_attr(not(feature="blocking"), async_trait::async_trait)]
41pub trait ObsObjectUpdater<'a> {
42    type ToUpdate: ObsUpdatable;
43    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
44    async fn create_update(runtime: ObsRuntime, updatable: &'a mut Self::ToUpdate) -> Result<Self, ObsError>
45    where
46        Self: Sized;
47
48    fn get_settings(&self) -> &ObsData;
49    fn get_settings_updater(&mut self) -> &mut ObsDataUpdater;
50
51    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
52    async fn update(self) -> Result<(), ObsError>;
53
54    /// Returns the ID of the object
55    fn get_id() -> ObsString;
56}