use alloc::boxed::Box;
use luaur_common::LUAU_ASSERT;
#[allow(non_camel_case_types)]
pub struct ScopedExit {
pub(crate) func: Option<Box<dyn FnOnce()>>,
}
impl ScopedExit {
#[allow(non_snake_case)]
pub fn new(f: Box<dyn FnOnce()>) -> Self {
LUAU_ASSERT!(true); Self { func: Some(f) }
}
}
impl Default for ScopedExit {
fn default() -> Self {
Self { func: None }
}
}
impl Drop for ScopedExit {
fn drop(&mut self) {
if let Some(f) = self.func.take() {
f();
}
}
}
#[allow(non_snake_case)]
impl ScopedExit {
pub fn move_from(&mut self, other: &mut Self) {
self.func = other.func.take();
}
}
unsafe impl Send for ScopedExit {}
unsafe impl Sync for ScopedExit {}