Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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