From 039790909b681237dd9e63494ce2c2cd29b220c3 Mon Sep 17 00:00:00 2001 From: Jerzy Wilczek Date: Thu, 31 Oct 2024 13:35:28 +0100 Subject: [PATCH] Change the `DropCallback` API to use `FnOnce` instead of `FnMut` --- CHANGELOG.md | 6 ++++++ wgpu-hal/src/lib.rs | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d130b0ee..b3999f0cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,12 @@ Bottom level categories: - Parse `diagnostic(…)` directives, but don't implement any triggering rules yet. By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456). +### Changes + +#### HAL + +- Change the `DropCallback` API to use `FnOnce` instead of `FnMut`. By @jerzywilczek in [#6482](https://github.com/gfx-rs/wgpu/pull/6482) + ## 23.0.0 (2024-10-25) ### Themes of this release diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 6578252c1a..0cddb69976 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -305,24 +305,28 @@ pub type AtomicFenceValue = std::sync::atomic::AtomicU64; /// A callback to signal that wgpu is no longer using a resource. #[cfg(any(gles, vulkan))] -pub type DropCallback = Box; +pub type DropCallback = Box; #[cfg(any(gles, vulkan))] pub struct DropGuard { - callback: DropCallback, + callback: Option, } #[cfg(all(any(gles, vulkan), any(native, Emscripten)))] impl DropGuard { fn from_option(callback: Option) -> Option { - callback.map(|callback| Self { callback }) + callback.map(|callback| Self { + callback: Some(callback), + }) } } #[cfg(any(gles, vulkan))] impl Drop for DropGuard { fn drop(&mut self) { - (self.callback)(); + if let Some(cb) = self.callback.take() { + (cb)(); + } } }