Skip to main content

mono_rt/types/
mono_type.rs

1use super::{MonoDomain, MonoObject, TypeKind, mono_handle};
2use crate::{Result, api};
3
4mono_handle!(MonoType);
5
6impl MonoType {
7    /// Returns a [`MonoObject`] wrapping this type descriptor in the given domain.
8    ///
9    /// # Errors
10    ///
11    /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
12    pub fn object(self, domain: MonoDomain) -> Result<Option<MonoObject>> {
13        let ptr = api()?.type_get_object(domain.as_ptr(), self.as_ptr());
14        Ok(MonoObject::from_ptr(ptr))
15    }
16
17    /// Returns the [`TypeKind`] discriminant identifying what kind of type this is.
18    ///
19    /// # Errors
20    ///
21    /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
22    pub fn kind(self) -> Result<TypeKind> {
23        let raw = api()?.type_get_type(self.as_ptr());
24        Ok(TypeKind::from(raw))
25    }
26}