mono_rt/types/domain.rs
1use std::ffi::CString;
2
3use super::{MonoAssembly, mono_handle};
4use crate::{MonoError, Result, api};
5
6mono_handle!(MonoDomain);
7
8impl MonoDomain {
9 /// Returns the root domain of the Mono runtime.
10 ///
11 /// # Errors
12 ///
13 /// Returns [`MonoError::Uninitialized`] if the Mono API has not been initialized.
14 pub fn root() -> Result<Option<Self>> {
15 let ptr = api()?.get_root_domain();
16 Ok(Self::from_ptr(ptr))
17 }
18
19 /// Opens (loads) an assembly from the given file path into this domain.
20 ///
21 /// # Errors
22 ///
23 /// Returns [`MonoError::NullByteInName`] if `path` contains an interior null byte.
24 /// Returns [`MonoError::Uninitialized`] if the Mono API has not been initialized.
25 pub fn open_assembly(self, path: &str) -> Result<Option<MonoAssembly>> {
26 let c_path = CString::new(path).map_err(|_| MonoError::NullByteInName)?;
27 let ptr = api()?.domain_assembly_open(self.as_ptr(), c_path.as_ptr());
28 Ok(MonoAssembly::from_ptr(ptr))
29 }
30}