Skip to main content

uika_ffi/
handles.rs

1use std::ffi::c_void;
2
3/// Opaque handle to a UObject. Rust never dereferences — it is a C++ side identifier.
4#[repr(transparent)]
5#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
6pub struct UObjectHandle(pub *mut c_void);
7
8/// Opaque handle to a UClass.
9#[repr(transparent)]
10#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
11pub struct UClassHandle(pub *mut c_void);
12
13/// Opaque handle to an FProperty.
14#[repr(transparent)]
15#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
16pub struct FPropertyHandle(pub *mut c_void);
17
18/// Opaque handle to a UFunction. Only used for reify (Phase 9);
19/// normal function calls go through func_table.
20#[repr(transparent)]
21#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
22pub struct UFunctionHandle(pub *mut c_void);
23
24/// Opaque handle to a UScriptStruct.
25#[repr(transparent)]
26#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
27pub struct UStructHandle(pub *mut c_void);
28
29/// FName stored as a raw 64-bit value (ComparisonIndex + Number).
30#[repr(transparent)]
31#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
32pub struct FNameHandle(pub u64);
33
34/// Weak object pointer: ObjectIndex + ObjectSerialNumber (matches UE FWeakObjectPtr layout).
35#[repr(C)]
36#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
37pub struct FWeakObjectHandle {
38    pub object_index: i32,
39    pub object_serial_number: i32,
40}
41
42impl Default for FWeakObjectHandle {
43    fn default() -> Self {
44        FWeakObjectHandle {
45            object_index: -1,
46            object_serial_number: 0,
47        }
48    }
49}
50
51// Handles are raw FFI identifiers. They can be sent across threads
52// (but must only be *used* on the game thread).
53// Sync is needed for OnceLock caching in generated code.
54unsafe impl Send for UObjectHandle {}
55unsafe impl Sync for UObjectHandle {}
56unsafe impl Send for UClassHandle {}
57unsafe impl Sync for UClassHandle {}
58unsafe impl Send for FPropertyHandle {}
59unsafe impl Sync for FPropertyHandle {}
60unsafe impl Send for UFunctionHandle {}
61unsafe impl Sync for UFunctionHandle {}
62unsafe impl Send for UStructHandle {}
63unsafe impl Sync for UStructHandle {}
64unsafe impl Send for FWeakObjectHandle {}
65unsafe impl Sync for FWeakObjectHandle {}