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