Skip to content

Commit

Permalink
feat: add {Operations,LoadOp}::map_clear_value
Browse files Browse the repository at this point in the history
This makes some operations easier in FFI contexts for Firefox, like
mapping `Option<&T>` to `Option<T>`.
  • Loading branch information
ErichDonGubler committed Jan 22, 2025
1 parent 3dd925b commit 9c94946
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4964,6 +4964,18 @@ pub enum LoadOp<V> {
}

impl<V> LoadOp<V> {
/// Map this operation's type to another, migrating the [`Self::Clear`] value via `f`, if
/// necessary.
pub fn map_clear_value<T, F>(self, f: F) -> LoadOp<T>
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<T>(&self, other: LoadOp<T>) -> bool {
matches!(
Expand Down Expand Up @@ -5028,6 +5040,21 @@ impl<V: Default> Default for Operations<V> {
}
}

impl<V> Operations<V> {
/// Map these operations' type to another, migrating the clear value of [`Self::load`], if
/// necessary, using `f`.
pub fn map_clear_value<T, F>(self, f: F) -> Operations<T>
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`](
Expand Down

0 comments on commit 9c94946

Please sign in to comment.