pub struct MonoMethod(/* private fields */);Expand description
An opaque handle to a Mono runtime object.
§Thread safety
This type is intentionally !Send + !Sync. Every thread that reads or writes
Mono objects must first be registered with the runtime via
crate::MonoThreadGuard::attach. Using a handle on an unregistered thread is
undefined behavior — Mono’s garbage collector and internal bookkeeping assume all
active threads are known to the runtime.
Handles are therefore bound to the thread on which they were obtained. The
compiler enforces this: a handle cannot be moved to another thread without
explicit unsafe code.
If you need to transfer a handle across thread boundaries and you can guarantee that both threads are attached to the runtime for the entire duration of use, you can opt in manually on your wrapper type:
struct MyComponent {
class: mono_rt::MonoClass,
}
// SAFETY: `class` is only accessed while the calling thread holds a
// `MonoThreadGuard`, ensuring it is registered with the Mono runtime.
unsafe impl Send for MyComponent {}
unsafe impl Sync for MyComponent {}Implementations§
Source§impl MonoMethod
impl MonoMethod
Source§impl MonoMethod
impl MonoMethod
Sourcepub fn name(self) -> Result<String>
pub fn name(self) -> Result<String>
Returns the name of this method as reported by the Mono runtime.
The returned string is copied out of Mono’s metadata and is safe to use beyond the lifetime of the runtime handle.
§Errors
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub unsafe fn invoke(
self,
obj: *mut c_void,
args: *mut *mut c_void,
) -> Result<Option<MonoObject>>
pub unsafe fn invoke( self, obj: *mut c_void, args: *mut *mut c_void, ) -> Result<Option<MonoObject>>
Invokes the method on obj (null for static methods) with the given arguments.
Returns Ok(Some(result)) on success, Ok(None) when the method returns void, and
Err(MonoError::ManagedException(exc)) when the invocation throws a managed exception.
§Errors
Returns MonoError::ManagedException when a managed exception is thrown.
Returns MonoError::Uninitialized if the Mono API has not been initialized.
§Safety
obj and args must be valid Mono objects/arguments matching the method signature.
Sourcepub unsafe fn invoke_with(
self,
obj: *mut c_void,
args: &[Value],
) -> Result<Option<MonoObject>>
pub unsafe fn invoke_with( self, obj: *mut c_void, args: &[Value], ) -> Result<Option<MonoObject>>
Typed variant of invoke: builds the args array from args automatically.
Prefer this over invoke when argument types are known at compile time. The caller is still
responsible for matching the Value variants to the method’s actual parameter types.
§Errors
Returns MonoError::ManagedException when a managed exception is thrown.
Returns MonoError::Uninitialized if the Mono API has not been initialized.
§Safety
obj must be a valid Mono object pointer (or null for static methods). Each Value
in args must correspond to the correct parameter type expected by the method.
Trait Implementations§
Source§impl Clone for MonoMethod
impl Clone for MonoMethod
Source§fn clone(&self) -> MonoMethod
fn clone(&self) -> MonoMethod
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more