#[cfg(feature = "libloading")]
pub mod libloading;
#[cfg(not(feature = "sync"))]
pub type LockGuard<'a, T> = std::cell::Ref<'a, T>;
#[cfg(not(feature = "sync"))]
pub type LockGuardMut<'a, T> = std::cell::RefMut<'a, T>;
#[cfg(feature = "sync")]
#[allow(dead_code)]
pub type LockGuard<'a, T> = std::sync::RwLockReadGuard<'a, T>;
#[cfg(feature = "sync")]
#[allow(dead_code)]
pub type LockGuardMut<'a, T> = std::sync::RwLockWriteGuard<'a, T>;
#[allow(dead_code)]
pub fn locked_write<T>(value: &'_ rhai::Locked<T>) -> LockGuardMut<'_, T> {
#[cfg(not(feature = "sync"))]
return value.borrow_mut();
#[cfg(feature = "sync")]
return value.write().unwrap();
}
#[allow(dead_code)]
pub fn locked_read<T>(value: &'_ rhai::Locked<T>) -> LockGuard<'_, T> {
#[cfg(not(feature = "sync"))]
return value.borrow();
#[cfg(feature = "sync")]
return value.read().unwrap();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn locked_write_and_read() {
let value = rhai::Locked::new(0i32);
*locked_write(&value) = 42;
assert_eq!(*locked_read(&value), 42);
}
}