Tweak MapPassErr to work for both errors and results (#7780)

This commit is contained in:
Andy Leiserson 2025-06-10 10:26:36 -07:00 committed by GitHub
parent 54d30da44a
commit 24f779696b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 20 deletions

View File

@ -1519,15 +1519,15 @@ impl RenderBundleError {
}
}
impl<T, E> MapPassErr<T, RenderBundleError> for Result<T, E>
impl<E> MapPassErr<RenderBundleError> for E
where
E: Into<RenderBundleErrorInner>,
{
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, RenderBundleError> {
self.map_err(|inner| RenderBundleError {
fn map_pass_err(self, scope: PassErrorScope) -> RenderBundleError {
RenderBundleError {
scope,
inner: inner.into(),
})
inner: self.into(),
}
}
}

View File

@ -182,15 +182,15 @@ pub struct ComputePassError {
pub(super) inner: ComputePassErrorInner,
}
impl<T, E> MapPassErr<T, ComputePassError> for Result<T, E>
impl<E> MapPassErr<ComputePassError> for E
where
E: Into<ComputePassErrorInner>,
{
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, ComputePassError> {
self.map_err(|inner| ComputePassError {
fn map_pass_err(self, scope: PassErrorScope) -> ComputePassError {
ComputePassError {
scope,
inner: inner.into(),
})
inner: self.into(),
}
}
}

View File

@ -1029,8 +1029,17 @@ impl Default for BindGroupStateChange {
}
}
trait MapPassErr<T, O> {
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, O>;
trait MapPassErr<T> {
fn map_pass_err(self, scope: PassErrorScope) -> T;
}
impl<T, E, F> MapPassErr<Result<T, F>> for Result<T, E>
where
E: MapPassErr<F>,
{
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, F> {
self.map_err(|err| err.map_pass_err(scope))
}
}
#[derive(Clone, Copy, Debug)]

View File

@ -807,15 +807,12 @@ pub struct RenderPassError {
pub(super) inner: RenderPassErrorInner,
}
impl<T, E> MapPassErr<T, RenderPassError> for Result<T, E>
where
E: Into<RenderPassErrorInner>,
{
fn map_pass_err(self, scope: PassErrorScope) -> Result<T, RenderPassError> {
self.map_err(|inner| RenderPassError {
impl<E: Into<RenderPassErrorInner>> MapPassErr<RenderPassError> for E {
fn map_pass_err(self, scope: PassErrorScope) -> RenderPassError {
RenderPassError {
scope,
inner: inner.into(),
})
inner: self.into(),
}
}
}