Macro libil2cpp::unsafe_impl_reference_type
source · [−]unsafe_impl_reference_type!() { /* proc-macro */ }
Expand description
Implements the Type
trait for a Rust type that is equivalent to a C#
reference type
Note that in order to use this macros, the generic_associated_types
feature must be enabled.
Safety
The type must hold the guarantees required by the Type
trait.
Examples
The basic syntax follows the pattern in <libil2cpp path> for <Rust type> => <C# type>
.
ⓘ
#![feature(generic_associated_types)]
use libil2cpp::Il2CppObject;
#[repr(C)]
struct GameObject {
object: Il2CppObject,
}
unsafe_impl_reference_type!(in libil2cpp for GameObject => UnityEngine.GameObject);
It’s also possible to use this macro with generic types. In this scenario,
the once_cell
feature must also be enabled.
ⓘ
#![feature(generic_associated_types, once_cell)]
use libil2cpp::{Il2CppArray, Il2CppObject, Type};
#[repr(C)]
struct List<T: Type> {
object: Il2CppObject,
items: *mut Il2CppArray<T>,
size: i32,
}
unsafe_impl_reference_type!(in libil2cpp for List<T> => System.Collections.Generic.List<T>);
A class getter can be provided manually.
ⓘ
#![feature(generic_associated_types)]
use libil2cpp::Il2CppObject;
#[repr(C)]
struct MyClass {
object: Il2CppObject,
}
unsafe_impl_reference_type!(in libil2cpp for MyClass => MyNamespace.MyClass {
my_class_getter()
});
Finally, the namespace and class name can be provided as string literals. In this case, the macro will no change them in any way regardless of generic parameters.
ⓘ
#![feature(generic_associated_types, once_cell)]
use libil2cpp::{Il2CppArray, Il2CppObject, Type};
#[repr(C)]
struct List<T: Type> {
object: Il2CppObject,
items: *mut Il2CppArray<T>,
size: i32,
}
unsafe_impl_reference_type!(in libil2cpp for List<T> => "System.Collections.Generic"."List`1"<T>);