Skip to main content

il2cpp_bridge_rs/structs/core/runtime/
coroutine.rs

1//! Unity Coroutine wrapper
2use std::ffi::c_void;
3
4/// Wrapper around Unity's UnityEngine.Coroutine object
5///
6/// A Coroutine represents a running coroutine instance that can be
7/// used to stop the coroutine later.
8#[repr(transparent)]
9#[derive(Debug, Clone, Copy)]
10pub struct Coroutine {
11    /// Pointer to the IL2CPP Coroutine object
12    ptr: *mut c_void,
13}
14
15unsafe impl Send for Coroutine {}
16unsafe impl Sync for Coroutine {}
17
18impl Coroutine {
19    /// Creates a Coroutine from a raw pointer
20    ///
21    /// # Arguments
22    /// * `ptr` - The raw pointer to the IL2CPP Coroutine object
23    ///
24    /// # Returns
25    /// * `Self` - The created Coroutine wrapper
26    pub unsafe fn from_ptr(ptr: *mut c_void) -> Self {
27        Self { ptr }
28    }
29
30    /// Returns the raw pointer to the Coroutine object
31    ///
32    /// # Returns
33    /// * `*mut c_void` - The raw pointer
34    pub fn as_ptr(&self) -> *mut c_void {
35        self.ptr
36    }
37
38    /// Checks if the Coroutine pointer is null
39    ///
40    /// # Returns
41    /// * `bool` - True if the pointer is null
42    pub fn is_null(&self) -> bool {
43        self.ptr.is_null()
44    }
45}