libobs_wrapper\sources/
builder.rs

1use crate::{
2    data::ObsObjectBuilder,
3    scenes::{ObsSceneItemRef, ObsSceneRef, SceneItemExtSceneTrait},
4    sources::ObsSourceTrait,
5    utils::ObsError,
6};
7
8pub trait ObsSourceBuilder: ObsObjectBuilder {
9    type T: ObsSourceTrait + Clone + 'static;
10
11    fn build(self) -> Result<Self::T, ObsError>
12    where
13        Self: Sized;
14
15    /// Both items are returned: the source and the scene item it was added as.
16    /// You can safely drop these items, they are stored within the scene if you don't need them.
17    fn add_to_scene(self, scene: &mut ObsSceneRef) -> Result<ObsSceneItemRef<Self::T>, ObsError>
18    where
19        Self: Sized,
20    {
21        let source = self.build()?;
22
23        scene.add_source(source.clone())
24    }
25}