pub struct ObsRuntime { /* private fields */ }Expand description
Core runtime that manages the OBS thread
This struct represents the runtime environment for OBS operations. It creates and manages a dedicated thread for OBS API calls to ensure thread safety while allowing interaction from any thread.
§Thread Safety
ObsRuntime can be safely cloned and shared across threads. All operations
are automatically dispatched to the dedicated OBS thread.
§Lifecycle Management
When the last ObsRuntime instance is dropped, the OBS thread is automatically
shut down and all OBS resources are properly released.
Implementations§
Source§impl ObsRuntime
impl ObsRuntime
Sourcepub fn run_with_obs<F>(&self, operation: F) -> Result<()>
pub fn run_with_obs<F>(&self, operation: F) -> Result<()>
Executes an operation on the OBS thread without returning a value
This is a convenience wrapper around run_with_obs_result for operations
that don’t need to return a value.
§Parameters
operation- A function to execute on the OBS thread
§Returns
A Result indicating success or failure
§Examples
use libobs_wrapper::runtime::ObsRuntime;
async fn example(runtime: &ObsRuntime) {
runtime.run_with_obs(|| {
// This code runs on the OBS thread
println!("Hello from the OBS thread!");
}).await.unwrap();
}Sourcepub fn run_with_obs_result<F, T>(&self, operation: F) -> Result<T>
pub fn run_with_obs_result<F, T>(&self, operation: F) -> Result<T>
Executes an operation on the OBS thread and returns a result
This method dispatches a task to the OBS thread and blocks and waits for the result.
§Parameters
operation- A function to execute on the OBS thread
§Returns
A Result containing the value returned by the operation
§Examples
use libobs_wrapper::runtime::ObsRuntime;
async fn example(runtime: &ObsRuntime) {
let version = runtime.run_with_obs_result(|| {
// This code runs on the OBS thread
unsafe { libobs::obs_get_version_string() }
}).await.unwrap();
println!("OBS Version: {:?}", version);
}Trait Implementations§
Source§impl Clone for ObsRuntime
impl Clone for ObsRuntime
Source§fn clone(&self) -> ObsRuntime
fn clone(&self) -> ObsRuntime
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more