Skip to content

Commit 4e47ba4

Browse files
authored
[wgpu-hal] Change the DropCallback API to use FnOnce instead of FnMut (#6482)
1 parent 6b85e65 commit 4e47ba4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Bottom level categories:
4646

4747
- Parse `diagnostic(…)` directives, but don't implement any triggering rules yet. By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456).
4848

49+
### Changes
50+
51+
#### HAL
52+
53+
- Change the `DropCallback` API to use `FnOnce` instead of `FnMut`. By @jerzywilczek in [#6482](https://github.com/gfx-rs/wgpu/pull/6482)
54+
4955
## 23.0.0 (2024-10-25)
5056

5157
### Themes of this release

wgpu-hal/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,24 +305,28 @@ pub type AtomicFenceValue = std::sync::atomic::AtomicU64;
305305

306306
/// A callback to signal that wgpu is no longer using a resource.
307307
#[cfg(any(gles, vulkan))]
308-
pub type DropCallback = Box<dyn FnMut() + Send + Sync + 'static>;
308+
pub type DropCallback = Box<dyn FnOnce() + Send + Sync + 'static>;
309309

310310
#[cfg(any(gles, vulkan))]
311311
pub struct DropGuard {
312-
callback: DropCallback,
312+
callback: Option<DropCallback>,
313313
}
314314

315315
#[cfg(all(any(gles, vulkan), any(native, Emscripten)))]
316316
impl DropGuard {
317317
fn from_option(callback: Option<DropCallback>) -> Option<Self> {
318-
callback.map(|callback| Self { callback })
318+
callback.map(|callback| Self {
319+
callback: Some(callback),
320+
})
319321
}
320322
}
321323

322324
#[cfg(any(gles, vulkan))]
323325
impl Drop for DropGuard {
324326
fn drop(&mut self) {
325-
(self.callback)();
327+
if let Some(cb) = self.callback.take() {
328+
(cb)();
329+
}
326330
}
327331
}
328332

0 commit comments

Comments
 (0)