diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 6a19c6147d..6db3966890 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -4964,6 +4964,18 @@ pub enum LoadOp { } impl LoadOp { + /// Map this operation's type to another, migrating the [`Self::Clear`] value via `f`, if + /// necessary. + pub fn map_clear_value(self, f: F) -> LoadOp + where + F: FnOnce(V) -> T, + { + match self { + Self::Clear(value) => LoadOp::Clear(f(value)), + Self::Load => LoadOp::Load, + } + } + /// Returns true if variants are same (ignoring clear value) pub fn eq_variant(&self, other: LoadOp) -> bool { matches!( @@ -5028,6 +5040,21 @@ impl Default for Operations { } } +impl Operations { + /// Map these operations' type to another, migrating the clear value of [`Self::load`], if + /// necessary, using `f`. + pub fn map_clear_value(self, f: F) -> Operations + where + F: FnOnce(V) -> T, + { + let Self { load, store } = self; + Operations { + load: load.map_clear_value(f), + store, + } + } +} + /// Describes the depth/stencil state in a render pipeline. /// /// Corresponds to [WebGPU `GPUDepthStencilState`](