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.
§Examples
Creating a runtime:
use libobs_wrapper::runtime::ObsRuntime;
use libobs_wrapper::utils::StartupInfo;
async fn example() {
let startup_info = StartupInfo::default();
let (runtime, _, _) = match ObsRuntime::startup(startup_info).await.unwrap() {
ObsRuntimeReturn::Done(res) => res,
_ => panic!("OBS initialization failed"),
};
// Now you can use runtime to interact with OBS
}
Implementations§
Source§impl ObsRuntime
impl ObsRuntime
Sourcepub async fn run_with_obs<F>(&self, operation: F) -> Result<()>
pub async 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_blocking<F, T>(&self, operation: F) -> Result<T>
pub fn run_with_obs_result_blocking<F, T>(&self, operation: F) -> Result<T>
Executes an operation on the OBS thread and returns a result (blocking version)
This method blocks the current thread until the operation completes.
§Parameters
operation
- A function to execute on the OBS thread
§Returns
A Result
containing the value returned by the operation
§Panics
This function panics if called within an asynchronous execution context.
Sourcepub async fn run_with_obs_result<F, T>(&self, operation: F) -> Result<T>
pub async fn run_with_obs_result<F, T>(&self, operation: F) -> Result<T>
Executes an operation on the OBS thread and returns a result (async version)
This method dispatches a task to the OBS thread and asynchronously 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