Skip to content

Commit 1bdd8d9

Browse files
feat: add {Operations,LoadOp}::map_clear_value
This makes some operations easier in FFI contexts for Firefox, like mapping `Option<&T>` to `Option<T>`.
1 parent 894d036 commit 1bdd8d9

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

wgpu-types/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4393,6 +4393,18 @@ pub enum LoadOp<V> {
43934393
}
43944394

43954395
impl<V> LoadOp<V> {
4396+
/// Map this operation's type to another, migrating the [`Self::Clear`] value via `f`, if
4397+
/// necessary.
4398+
pub fn map_clear_value<T, F>(self, f: F) -> LoadOp<T>
4399+
where
4400+
F: FnOnce(V) -> T,
4401+
{
4402+
match self {
4403+
Self::Clear(value) => LoadOp::Clear(f(value)),
4404+
Self::Load => LoadOp::Load,
4405+
}
4406+
}
4407+
43964408
/// Returns true if variants are same (ignoring clear value)
43974409
pub fn eq_variant<T>(&self, other: LoadOp<T>) -> bool {
43984410
matches!(
@@ -4457,6 +4469,21 @@ impl<V: Default> Default for Operations<V> {
44574469
}
44584470
}
44594471

4472+
impl<V> Operations<V> {
4473+
/// Map these operations' type to another, migrating the clear value of [`Self::load`], if
4474+
/// necessary, using `f`.
4475+
pub fn map_clear_value<T, F>(self, f: F) -> Operations<T>
4476+
where
4477+
F: FnOnce(V) -> T,
4478+
{
4479+
let Self { load, store } = self;
4480+
Operations {
4481+
load: load.map_clear_value(f),
4482+
store,
4483+
}
4484+
}
4485+
}
4486+
44604487
/// Describes the depth/stencil state in a render pipeline.
44614488
///
44624489
/// Corresponds to [WebGPU `GPUDepthStencilState`](

0 commit comments

Comments
 (0)