pub struct MonoClass(/* 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 MonoClass
impl MonoClass
Sourcepub fn field(self, name: &str) -> Result<Option<MonoClassField>>
pub fn field(self, name: &str) -> Result<Option<MonoClassField>>
Looks up a field by name on this class.
§Errors
Returns MonoError::NullByteInName if name contains an interior null byte.
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub fn method(
self,
name: &str,
param_count: Option<i32>,
) -> Result<Option<MonoMethod>>
pub fn method( self, name: &str, param_count: Option<i32>, ) -> Result<Option<MonoMethod>>
Looks up a method by name on this class.
param_count restricts the search to a specific arity; pass None to match any overload.
§Errors
Returns MonoError::NullByteInName if name contains an interior null byte.
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub fn mono_type(self) -> Result<Option<MonoType>>
pub fn mono_type(self) -> Result<Option<MonoType>>
Returns the MonoType descriptor for this class.
§Errors
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub fn vtable(self, domain: MonoDomain) -> Result<Option<MonoVTable>>
pub fn vtable(self, domain: MonoDomain) -> Result<Option<MonoVTable>>
Returns the vtable for this class in the given domain.
§Errors
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub fn new_object(self, domain: MonoDomain) -> Result<Option<MonoObject>>
pub fn new_object(self, domain: MonoDomain) -> Result<Option<MonoObject>>
Allocates a new uninitialized instance of this class in the given domain.
The returned object is not yet constructed — call the .ctor method via
MonoMethod::invoke to initialize it.
§Errors
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub fn fields(self) -> Result<Vec<MonoClassField>>
pub fn fields(self) -> Result<Vec<MonoClassField>>
Returns all fields declared on this class.
§Errors
Returns MonoError::Uninitialized if the Mono API has not been initialized.
Sourcepub fn methods(self) -> Result<Vec<MonoMethod>>
pub fn methods(self) -> Result<Vec<MonoMethod>>
Returns all methods declared on this class.
§Errors
Returns MonoError::Uninitialized if the Mono API has not been initialized.