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 subclass_of;
17pub mod struct_ref;
18pub mod pinned;
19pub mod dynamic_call;
20pub mod logging;
21pub mod ffi_guard;
22pub mod containers;
23pub mod delegate_registry;
24pub mod reify_registry;
25pub mod ue_math;
26pub mod fname;
27pub mod weak_ptr;
28pub mod widget;
29pub mod input;
30pub mod world;
31pub mod soft_ref;
32
33// Re-export the primary public API surface.
34pub use api::{api, init_api};
35pub use error::{check_ffi, check_ffi_ctx, ffi_infallible, ffi_infallible_ctx, RustealError, RustealResult};
36pub use traits::{UeClass, UeStruct, UeEnum, UeHandle, ValidHandle, HasParent, Inherits};
37pub use object_ref::{Checked, ObjectPointer, UObjectRef};
38pub use subclass_of::SubclassOf;
39pub use soft_ref::SoftObjectRef;
40pub use struct_ref::UStructRef;
41pub use pinned::Pinned;
42pub use dynamic_call::{DynamicCall, DynamicCallResult};
43pub use logging::{LOG_DISPLAY, LOG_WARNING, LOG_ERROR};
44pub use ffi_guard::ffi_boundary;
45pub use containers::{ContainerElement, OwnedStruct, UeArray, UeMap, UeSet};
46pub use delegate_registry::DelegateBinding;
47
48// Phase 10 re-exports.
49pub use fname::FName;
50pub use struct_ref::{OutRef, out_ref_from_param, struct_ref_from_param};
51pub use weak_ptr::TWeakObjectPtr;
52pub use ue_math::{
53    Rotator, Transform, LinearColor, Color,
54    Plane, Ray, Sphere, UeBox, UeBox2d, BoxSphereBounds,
55};
56
57// Re-export FFI types needed by generated code in rusteal-bindings.
58pub use rusteal_ffi::{
59    UObjectHandle, UClassHandle, FPropertyHandle, UStructHandle,
60    FNameHandle, FWeakObjectHandle, RustealErrorCode,
61};
62
63// ---------------------------------------------------------------------------
64// Lock helpers — recover from mutex poisoning instead of panicking
65// ---------------------------------------------------------------------------
66
67use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
68
69/// Lock a Mutex, recovering from poison.
70pub(crate) fn lock_or_recover<T>(m: &Mutex<T>) -> MutexGuard<'_, T> {
71    m.lock().unwrap_or_else(|e| e.into_inner())
72}
73
74/// Read-lock a RwLock, recovering from poison.
75pub(crate) fn read_or_recover<T>(m: &RwLock<T>) -> RwLockReadGuard<'_, T> {
76    m.read().unwrap_or_else(|e| e.into_inner())
77}
78
79/// Write-lock a RwLock, recovering from poison.
80pub(crate) fn write_or_recover<T>(m: &RwLock<T>) -> RwLockWriteGuard<'_, T> {
81    m.write().unwrap_or_else(|e| e.into_inner())
82}