Skip to content

Commit a87505f

Browse files
committed
feat(types)!: Add lifetimes to map_label-style helpers
1 parent 04a7fe8 commit a87505f

9 files changed

Lines changed: 26 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
171171
- Added new `InvalidWorkgroupSizeError`, which is now used by `DrawError::InvalidGroupSize` and `StageError::InvalidWorkgroupSize`.
172172
- Added `BuildAccelerationStructureError` variant `OffsetLimitedTo4GB` and changed `IndirectBufferOverrun` to contain offset and size rather than start and end offsets.
173173
- `IndexFormat::byte_size` now returns `u32` instead of `usize`.
174+
- BREAKING: `map_label` helpers have changed slightly. By @beicause and @andyleiserson in [#9480](https://github.com/gfx-rs/wgpu/pull/9480), [#9481](https://github.com/gfx-rs/wgpu/pull/9481), and [#9526](https://github.com/gfx-rs/wgpu/pull/9526).
175+
- `SurfaceConfiguration::map_label` and `SurfaceConfiguration::map_view_formats` now take `FnOnce(&V)` instead of `FnOnce(V)`.
176+
- All `map_label` helpers except `CreateShaderModuleDescriptorPassthrough` now have the signature `map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K)` (previously the lifetimes were implicit and thus could differ).
174177

175178
#### Validation
176179

wgpu-types/src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct BufferDescriptor<L> {
3434
impl<L> BufferDescriptor<L> {
3535
/// Takes a closure and maps the label of the buffer descriptor into another.
3636
#[must_use]
37-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> BufferDescriptor<K> {
37+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> BufferDescriptor<K> {
3838
BufferDescriptor {
3939
label: fun(&self.label),
4040
size: self.size,

wgpu-types/src/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct DeviceDescriptor<L> {
3737
impl<L> DeviceDescriptor<L> {
3838
/// Takes a closure and maps the label of the device descriptor into another.
3939
#[must_use]
40-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> DeviceDescriptor<K> {
40+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> DeviceDescriptor<K> {
4141
DeviceDescriptor {
4242
label: fun(&self.label),
4343
required_features: self.required_features,

wgpu-types/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ pub struct CommandEncoderDescriptor<L> {
403403
impl<L> CommandEncoderDescriptor<L> {
404404
/// Takes a closure and maps the label of the command encoder descriptor into another.
405405
#[must_use]
406-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CommandEncoderDescriptor<K> {
406+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CommandEncoderDescriptor<K> {
407407
CommandEncoderDescriptor {
408408
label: fun(&self.label),
409409
}
@@ -489,7 +489,7 @@ pub struct CommandBufferDescriptor<L> {
489489
impl<L> CommandBufferDescriptor<L> {
490490
/// Takes a closure and maps the label of the command buffer descriptor into another.
491491
#[must_use]
492-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CommandBufferDescriptor<K> {
492+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CommandBufferDescriptor<K> {
493493
CommandBufferDescriptor {
494494
label: fun(&self.label),
495495
}

wgpu-types/src/ray_tracing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct CreateBlasDescriptor<L> {
8686

8787
impl<L> CreateBlasDescriptor<L> {
8888
/// Takes a closure and maps the label of the blas descriptor into another.
89-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CreateBlasDescriptor<K> {
89+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CreateBlasDescriptor<K> {
9090
CreateBlasDescriptor {
9191
label: fun(&self.label),
9292
flags: self.flags,
@@ -112,7 +112,7 @@ pub struct CreateTlasDescriptor<L> {
112112

113113
impl<L> CreateTlasDescriptor<L> {
114114
/// Takes a closure and maps the label of the blas descriptor into another.
115-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CreateTlasDescriptor<K> {
115+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CreateTlasDescriptor<K> {
116116
CreateTlasDescriptor {
117117
label: fun(&self.label),
118118
flags: self.flags,

wgpu-types/src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ pub struct RenderBundleDescriptor<L> {
929929
impl<L> RenderBundleDescriptor<L> {
930930
/// Takes a closure and maps the label of the render bundle descriptor into another.
931931
#[must_use]
932-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> RenderBundleDescriptor<K> {
932+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> RenderBundleDescriptor<K> {
933933
RenderBundleDescriptor {
934934
label: fun(&self.label),
935935
}

wgpu-types/src/surface.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ pub struct SurfaceConfiguration<V> {
241241

242242
impl<V: Clone> SurfaceConfiguration<V> {
243243
/// Map `view_formats` of the texture descriptor into another.
244-
pub fn map_view_formats<M>(&self, fun: impl FnOnce(V) -> M) -> SurfaceConfiguration<M> {
244+
pub fn map_view_formats<'a, M>(
245+
&'a self,
246+
fun: impl FnOnce(&'a V) -> M,
247+
) -> SurfaceConfiguration<M> {
245248
SurfaceConfiguration {
246249
usage: self.usage,
247250
format: self.format,
@@ -250,7 +253,7 @@ impl<V: Clone> SurfaceConfiguration<V> {
250253
present_mode: self.present_mode,
251254
desired_maximum_frame_latency: self.desired_maximum_frame_latency,
252255
alpha_mode: self.alpha_mode,
253-
view_formats: fun(self.view_formats.clone()),
256+
view_formats: fun(&self.view_formats),
254257
}
255258
}
256259
}

wgpu-types/src/texture.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ pub struct TextureViewDescriptor<L> {
480480
impl<L> TextureViewDescriptor<L> {
481481
/// Takes a closure and maps the label of the texture view descriptor into another.
482482
#[must_use]
483-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
483+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> TextureViewDescriptor<K> {
484484
TextureViewDescriptor {
485485
label: fun(&self.label),
486486
format: self.format,
@@ -530,7 +530,7 @@ pub struct TextureDescriptor<L, V> {
530530
impl<L, V> TextureDescriptor<L, V> {
531531
/// Takes a closure and maps the label of the texture descriptor into another.
532532
#[must_use]
533-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureDescriptor<K, V>
533+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> TextureDescriptor<K, V>
534534
where
535535
V: Clone,
536536
{
@@ -548,10 +548,10 @@ impl<L, V> TextureDescriptor<L, V> {
548548

549549
/// Maps the label and view formats of the texture descriptor into another.
550550
#[must_use]
551-
pub fn map_label_and_view_formats<K, M>(
552-
&self,
553-
l_fun: impl FnOnce(&L) -> K,
554-
v_fun: impl FnOnce(&V) -> M,
551+
pub fn map_label_and_view_formats<'a, K, M>(
552+
&'a self,
553+
l_fun: impl FnOnce(&'a L) -> K,
554+
v_fun: impl FnOnce(&'a V) -> M,
555555
) -> TextureDescriptor<K, M> {
556556
TextureDescriptor {
557557
label: l_fun(&self.label),
@@ -703,7 +703,7 @@ impl<L: Default> Default for SamplerDescriptor<L> {
703703
impl<L> SamplerDescriptor<L> {
704704
/// Takes a closure and maps the label of the sampler descriptor into another.
705705
#[must_use]
706-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> SamplerDescriptor<K> {
706+
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> SamplerDescriptor<K> {
707707
SamplerDescriptor {
708708
label: fun(&self.label),
709709
address_mode_u: self.address_mode_u,

wgpu-types/src/texture/external_texture.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ pub struct ExternalTextureDescriptor<L> {
141141
impl<L> ExternalTextureDescriptor<L> {
142142
/// Takes a closure and maps the label of the external texture descriptor into another.
143143
#[must_use]
144-
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> ExternalTextureDescriptor<K> {
144+
pub fn map_label<'a, K>(
145+
&'a self,
146+
fun: impl FnOnce(&'a L) -> K,
147+
) -> ExternalTextureDescriptor<K> {
145148
ExternalTextureDescriptor {
146149
label: fun(&self.label),
147150
width: self.width,

0 commit comments

Comments
 (0)