rhai_dylib/module_resolvers/
mod.rs

1/// Libloading module resolver
2#[cfg(feature = "libloading")]
3pub mod libloading;
4
5// NOTE: Both of the following functions are rhai's internal and can't be accessed.
6// TODO: Ask to make this API public.
7
8/// Read-only lock guard for synchronized shared object.
9#[cfg(not(feature = "sync"))]
10pub type LockGuard<'a, T> = std::cell::Ref<'a, T>;
11
12/// Mutable lock guard for synchronized shared object.
13#[cfg(not(feature = "sync"))]
14pub type LockGuardMut<'a, T> = std::cell::RefMut<'a, T>;
15
16/// Read-only lock guard for synchronized shared object.
17#[cfg(feature = "sync")]
18#[allow(dead_code)]
19pub type LockGuard<'a, T> = std::sync::RwLockReadGuard<'a, T>;
20
21/// Mutable lock guard for synchronized shared object.
22#[cfg(feature = "sync")]
23#[allow(dead_code)]
24pub type LockGuardMut<'a, T> = std::sync::RwLockWriteGuard<'a, T>;
25
26/// Lock a [`Locked`] resource for mutable access.
27///
28/// # Panics
29///
30/// This function will return an error if the `RwLock` is poisoned.
31#[allow(dead_code)]
32pub fn locked_write<T>(value: &'_ rhai::Locked<T>) -> LockGuardMut<'_, T> {
33    #[cfg(not(feature = "sync"))]
34    return value.borrow_mut();
35
36    #[cfg(feature = "sync")]
37    return value.write().unwrap();
38}
39
40/// Lock a [`Locked`] resource for mutable access.
41///
42/// # Panics
43///
44/// This function will return an error if the `RwLock` is poisoned.
45#[allow(dead_code)]
46pub fn locked_read<T>(value: &'_ rhai::Locked<T>) -> LockGuard<'_, T> {
47    #[cfg(not(feature = "sync"))]
48    return value.borrow();
49
50    #[cfg(feature = "sync")]
51    return value.read().unwrap();
52}