diff --git a/src/helper.rs b/src/helper.rs index 32e3205..949e7ef 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -1,27 +1,32 @@ +pub struct Cleanup { + func: T, +} + +impl Drop for Cleanup +where + T: Fn(), +{ + fn drop(&mut self) { + (self.func)(); + } +} + +impl Cleanup +where + T: Fn(), +{ + pub fn new(func: T) -> Self { + Self { func } + } +} + #[macro_export] macro_rules! cleanup_func { (func: $cleanup_fn:expr, - name: $name:ident, hold_name: $hold_name:ident, $(var_pair: $orig_var:expr, $new_var:ident),*) => { $(let $new_var = $orig_var;)* - struct $name { - func: T, - } - impl Drop for $name where T: Fn() { - fn drop(&mut self) { - (self.func)(); - } - } - impl $name where T: Fn() { - fn new(func: T) -> Self { - Self { - func, - } - } - } - - $hold_name = $name::new($cleanup_fn); + $hold_name = crate::helper::Cleanup::new($cleanup_fn); } } diff --git a/src/main.rs b/src/main.rs index be9e690..124fc99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1643,7 +1643,6 @@ impl VulkanApp { ffi::vkDestroyBuffer(device_copy, staging_buf_copy, std::ptr::null()); ffi::vkFreeMemory(device_copy, staging_buf_mem_copy, std::ptr::null()); }, - name: CleanupStaging, hold_name: _inst, var_pair: self.device, device_copy, var_pair: staging_buffer, staging_buf_copy, @@ -1883,7 +1882,6 @@ impl VulkanApp { ffi::vkDestroyBuffer(device_copy, buf_copy, std::ptr::null()); ffi::vkFreeMemory(device_copy, buf_mem_copy, std::ptr::null()); }, - name: CleanupIdxStaging, hold_name: _staging_inst, var_pair: self.device, device_copy, var_pair: buf, buf_copy,