mono_rt/types/array.rs
1use super::mono_handle;
2use crate::{Result, api};
3
4mono_handle!(MonoArray);
5
6impl MonoArray {
7 /// Returns the number of elements in this array.
8 ///
9 /// # Errors
10 ///
11 /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
12 pub fn len(self) -> Result<usize> {
13 Ok(api()?.array_length(self.as_ptr()))
14 }
15
16 /// Returns `true` if the array contains no elements.
17 ///
18 /// # Errors
19 ///
20 /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
21 pub fn is_empty(self) -> Result<bool> {
22 Ok(self.len()? == 0)
23 }
24
25 /// Returns a pointer to the element at `index`, assuming each element is `size` bytes.
26 ///
27 /// # Errors
28 ///
29 /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
30 pub fn addr(self, size: i32, index: usize) -> Result<*mut c_void> {
31 Ok(api()?.array_addr_with_size(self.as_ptr(), size, index))
32 }
33}