Manually implement Error for ShaderError (#2160)

This commit is contained in:
Dzmitry Malyshau 2021-11-06 17:17:08 -04:00 committed by GitHub
parent 693bc58bdd
commit 7e00abf651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ use crate::{
id::{DeviceId, PipelineLayoutId, ShaderModuleId},
validation, Label, LifeGuard, Stored,
};
use std::{borrow::Cow, fmt};
use std::{borrow::Cow, error::Error, fmt};
use thiserror::Error;
#[allow(clippy::large_enum_variant)]
@ -46,11 +46,10 @@ impl<A: hal::Api> Resource for ShaderModule<A> {
}
}
#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug)]
pub struct ShaderError<E> {
pub source: String,
pub label: Option<String>,
#[source]
pub inner: E,
}
impl fmt::Display for ShaderError<naga::front::wgsl::ParseError> {
@ -91,6 +90,15 @@ impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>>
)
}
}
impl<E> Error for ShaderError<E>
where
ShaderError<E>: fmt::Display,
E: Error + 'static,
{
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.inner)
}
}
//Note: `Clone` would require `WithSpan: Clone`.
#[derive(Debug, Error)]