uika_runtime/traits.rs
1// Marker traits for UE reflection types. Codegen generates impls for all
2// exported UClasses, UStructs, and UEnums.
3
4use uika_ffi::{UClassHandle, UObjectHandle, UStructHandle};
5
6use crate::error::UikaResult;
7
8/// Implemented by codegen for every exported UClass.
9///
10/// Provides the static UClass handle needed for cast checks and reflection
11/// queries. The handle is typically cached in a `OnceLock` on first access.
12pub trait UeClass: 'static {
13 /// Get the UClass* for this type (cached after first call).
14 fn static_class() -> UClassHandle;
15}
16
17/// Implemented by codegen for every exported UScriptStruct.
18pub trait UeStruct: 'static {
19 /// Get the UScriptStruct* for this type.
20 fn static_struct() -> UStructHandle;
21}
22
23/// Implemented by codegen for every exported UEnum.
24pub trait UeEnum: 'static {
25 /// The underlying integer representation (u8, i32, i64, etc.).
26 type Repr: Copy;
27}
28
29/// Trait for types that hold a UObject handle and can validate it.
30///
31/// Both `UObjectRef<T>` and `Pinned<T>` implement this, enabling fallible
32/// validity checks. For infallible access, use [`ValidHandle`] instead.
33pub trait UeHandle {
34 /// Return the raw handle if the object is alive, or `Err(ObjectDestroyed)`.
35 fn checked_handle(&self) -> UikaResult<UObjectHandle>;
36
37 /// Return the raw handle without validity check.
38 fn raw_handle(&self) -> UObjectHandle;
39}
40
41/// Trait for types that have been pre-validated and can provide a handle
42/// without fallibility. `Checked<T>` and `Pinned<T>` implement this.
43///
44/// Codegen extension traits use this as a supertrait so that methods
45/// return `T` directly instead of `UikaResult<T>`.
46pub trait ValidHandle {
47 /// Return the raw handle. The implementor guarantees (or debug-asserts)
48 /// that the handle is valid.
49 fn handle(&self) -> UObjectHandle;
50}