Skip to content

Commit

Permalink
[wgpu-hal] Change the DropCallback API to use FnOnce instead of `…
Browse files Browse the repository at this point in the history
…FnMut` (#6482)
  • Loading branch information
jerzywilczek authored Oct 31, 2024
1 parent 6b85e65 commit 4e47ba4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)();
}
}
}

Expand Down

0 comments on commit 4e47ba4

Please sign in to comment.