[wgpu-hal] Change the DropCallback API to use FnOnce instead of FnMut (#6482)

This commit is contained in:
Jerzy Wilczek 2024-10-31 16:28:41 +01:00 committed by GitHub
parent 6b85e65f51
commit 4e47ba4ac0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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<dyn FnMut() + Send + Sync + 'static>;
pub type DropCallback = Box<dyn FnOnce() + Send + Sync + 'static>;
#[cfg(any(gles, vulkan))]
pub struct DropGuard {
callback: DropCallback,
callback: Option<DropCallback>,
}
#[cfg(all(any(gles, vulkan), any(native, Emscripten)))]
impl DropGuard {
fn from_option(callback: Option<DropCallback>) -> Option<Self> {
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)();
}
}
}