Skip to main content

rusteal_core/
lib.rs

1// rusteal-core: Safe Rust API wrapping rusteal-ffi.
2// All unsafe FFI calls are confined to this crate. Generated code and user
3// code interact only with the safe types exported here.
4
5pub mod api;
6pub mod error;
7pub mod traits;
8
9/// FFI dispatch wrappers: thin `unsafe` shims around the API table sub-tables.
10/// Auto-generated by `build.rs` from `rusteal-ffi/src/api_table.rs`.
11#[allow(unused_imports, unused_unsafe, unsafe_op_in_unsafe_fn, clippy::all)]
12pub mod ffi_dispatch {
13    include!(concat!(env!("OUT_DIR"), "/ffi_dispatch.rs"));
14}
15pub mod object_ref;
16pub mod struct_ref;
17pub mod pinned;
18pub mod dynamic_call;
19pub mod logging;
20pub mod ffi_guard;
21pub mod containers;
22pub mod delegate_registry;
23pub mod reify_registry;
24pub mod ue_math;
25pub mod fname;
26pub mod weak_ptr;
27pub mod widget;
28pub mod world;
29
30// Re-export the primary public API surface.
31pub use api::{api, init_api};
32pub use error::{check_ffi, check_ffi_ctx, ffi_infallible, ffi_infallible_ctx, RustealError, RustealResult};
33pub use traits::{UeClass, UeStruct, UeEnum, UeHandle, ValidHandle, HasParent};
34pub use object_ref::{Checked, UObjectRef};
35pub use struct_ref::UStructRef;
36pub use pinned::Pinned;
37pub use dynamic_call::{DynamicCall, DynamicCallResult};
38pub use logging::{LOG_DISPLAY, LOG_WARNING, LOG_ERROR};
39pub use ffi_guard::ffi_boundary;
40pub use containers::{ContainerElement, OwnedStruct, UeArray, UeMap, UeSet};
41pub use delegate_registry::DelegateBinding;
42
43// Phase 10 re-exports.
44pub use fname::FName;
45pub use struct_ref::struct_ref_from_param;
46pub use weak_ptr::TWeakObjectPtr;
47pub use ue_math::{
48    Rotator, Transform, LinearColor, Color,
49    Plane, Ray, Sphere, UeBox, UeBox2d, BoxSphereBounds,
50};
51
52// Re-export FFI types needed by generated code in rusteal-bindings.
53pub use rusteal_ffi::{
54    UObjectHandle, UClassHandle, FPropertyHandle, UStructHandle,
55    FNameHandle, FWeakObjectHandle, RustealErrorCode,
56};
57
58// ---------------------------------------------------------------------------
59// Lock helpers — recover from mutex poisoning instead of panicking
60// ---------------------------------------------------------------------------
61
62use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
63
64/// Lock a Mutex, recovering from poison.
65pub(crate) fn lock_or_recover<T>(m: &Mutex<T>) -> MutexGuard<'_, T> {
66    m.lock().unwrap_or_else(|e| e.into_inner())
67}
68
69/// Read-lock a RwLock, recovering from poison.
70pub(crate) fn read_or_recover<T>(m: &RwLock<T>) -> RwLockReadGuard<'_, T> {
71    m.read().unwrap_or_else(|e| e.into_inner())
72}
73
74/// Write-lock a RwLock, recovering from poison.
75pub(crate) fn write_or_recover<T>(m: &RwLock<T>) -> RwLockWriteGuard<'_, T> {
76    m.write().unwrap_or_else(|e| e.into_inner())
77}