Skip to content

Commit 24f7796

Browse files
Tweak MapPassErr to work for both errors and results (gfx-rs#7780)
1 parent 54d30da commit 24f7796

4 files changed

Lines changed: 26 additions & 20 deletions

File tree

wgpu-core/src/command/bundle.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,15 +1519,15 @@ impl RenderBundleError {
15191519
}
15201520
}
15211521

1522-
impl<T, E> MapPassErr<T, RenderBundleError> for Result<T, E>
1522+
impl<E> MapPassErr<RenderBundleError> for E
15231523
where
15241524
E: Into<RenderBundleErrorInner>,
15251525
{
1526-
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, RenderBundleError> {
1527-
self.map_err(|inner| RenderBundleError {
1526+
fn map_pass_err(self, scope: PassErrorScope) -> RenderBundleError {
1527+
RenderBundleError {
15281528
scope,
1529-
inner: inner.into(),
1530-
})
1529+
inner: self.into(),
1530+
}
15311531
}
15321532
}
15331533

wgpu-core/src/command/compute.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ pub struct ComputePassError {
182182
pub(super) inner: ComputePassErrorInner,
183183
}
184184

185-
impl<T, E> MapPassErr<T, ComputePassError> for Result<T, E>
185+
impl<E> MapPassErr<ComputePassError> for E
186186
where
187187
E: Into<ComputePassErrorInner>,
188188
{
189-
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, ComputePassError> {
190-
self.map_err(|inner| ComputePassError {
189+
fn map_pass_err(self, scope: PassErrorScope) -> ComputePassError {
190+
ComputePassError {
191191
scope,
192-
inner: inner.into(),
193-
})
192+
inner: self.into(),
193+
}
194194
}
195195
}
196196

wgpu-core/src/command/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,17 @@ impl Default for BindGroupStateChange {
10291029
}
10301030
}
10311031

1032-
trait MapPassErr<T, O> {
1033-
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, O>;
1032+
trait MapPassErr<T> {
1033+
fn map_pass_err(self, scope: PassErrorScope) -> T;
1034+
}
1035+
1036+
impl<T, E, F> MapPassErr<Result<T, F>> for Result<T, E>
1037+
where
1038+
E: MapPassErr<F>,
1039+
{
1040+
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, F> {
1041+
self.map_err(|err| err.map_pass_err(scope))
1042+
}
10341043
}
10351044

10361045
#[derive(Clone, Copy, Debug)]

wgpu-core/src/command/render.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,15 +807,12 @@ pub struct RenderPassError {
807807
pub(super) inner: RenderPassErrorInner,
808808
}
809809

810-
impl<T, E> MapPassErr<T, RenderPassError> for Result<T, E>
811-
where
812-
E: Into<RenderPassErrorInner>,
813-
{
814-
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, RenderPassError> {
815-
self.map_err(|inner| RenderPassError {
810+
impl<E: Into<RenderPassErrorInner>> MapPassErr<RenderPassError> for E {
811+
fn map_pass_err(self, scope: PassErrorScope) -> RenderPassError {
812+
RenderPassError {
816813
scope,
817-
inner: inner.into(),
818-
})
814+
inner: self.into(),
815+
}
819816
}
820817
}
821818

0 commit comments

Comments
 (0)