unity::il2cpp::object

Trait ArrayInstantiator

source
pub trait ArrayInstantiator<T> {
    // Required methods
    fn new(capacity: usize) -> Il2CppResult<&'static mut Self>;
    fn from_slice(slice: impl AsMut<[T]>) -> Il2CppResult<&'static mut Self>;
}
Expand description

Trait to abstract away the new methods for value types vs reference ones.

Required Methods§

source

fn new(capacity: usize) -> Il2CppResult<&'static mut Self>

Create an empty Il2CppArray capable of holding the provided amount of entries.

Arguments:

  • class: The class of the elements that are going to be stored.
  • capacity: The maximum amount of element that can be stored.

Example:

let new_array: Il2CppArray<u8> = Il2CppArray::<u8>::new(SystemByte::get_class(), 69).unwrap();
source

fn from_slice(slice: impl AsMut<[T]>) -> Il2CppResult<&'static mut Self>

Create a new Il2CppArray by copying the content of a slice into it.

Arguments:

  • class: The class of the elements that are going to be stored.
  • slice: The slice that’ll be copied into the Il2CppArray.

Example:

let mut slice: &mut [u8] = &[0x1, 0x2, 0x3];
let new_array: Il2CppArray<u8> = Il2CppArray::<u8>::new_from(SystemByte::get_class(), slice).unwrap();

Note that this method takes ownership of the slice, so you won’t be able to use it afterwards.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ArrayInstantiator<u8> for Array<u8>

source§

impl<'a, T: Il2CppClassData> ArrayInstantiator<&'a mut T> for Array<&'a mut T>

source§

impl<'a, T: Il2CppClassData> ArrayInstantiator<Option<&'a mut T>> for Array<Option<&'a mut T>>