[vello_shaders] Use thiserror::Error for the library Error type

This commit is contained in:
Arman Uguray 2023-03-29 10:12:23 -07:00
parent 14ab8d90ae
commit b52ef32c90
2 changed files with 22 additions and 25 deletions

View file

@ -5,13 +5,15 @@ edition = "2021"
[features]
default = ["compile", "wgsl", "msl"]
compile = ["naga"]
compile = ["naga", "thiserror"]
wgsl = []
msl = []
[dependencies]
naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"], optional = true }
thiserror = { version = "1.0.40", optional = true }
[build-dependencies]
naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"] }
thiserror = "1.0.40"

View file

@ -1,12 +1,14 @@
use naga::{
front::wgsl,
valid::{Capabilities, ModuleInfo, ValidationError, ValidationFlags},
AddressSpace, ImageClass, Module, StorageAccess, WithSpan,
};
use std::{
collections::{HashMap, HashSet},
path::Path,
use {
naga::{
front::wgsl,
valid::{Capabilities, ModuleInfo, ValidationError, ValidationFlags},
AddressSpace, ImageClass, Module, StorageAccess, WithSpan,
},
std::{
collections::{HashMap, HashSet},
path::Path,
},
thiserror::Error,
};
pub mod permutations;
@ -16,25 +18,18 @@ pub mod msl;
use crate::types::{BindType, BindingInfo};
#[derive(Debug)]
#[derive(Error, Debug)]
pub enum Error {
Parse(wgsl::ParseError),
Validate(WithSpan<ValidationError>),
#[error("failed to parse shader: {0}")]
Parse(#[from] wgsl::ParseError),
#[error("failed to validate shader: {0}")]
Validate(#[from] WithSpan<ValidationError>),
#[error("missing entry point function")]
EntryPointNotFound,
}
impl From<wgsl::ParseError> for Error {
fn from(e: wgsl::ParseError) -> Self {
Self::Parse(e)
}
}
impl From<WithSpan<ValidationError>> for Error {
fn from(e: WithSpan<ValidationError>) -> Self {
Self::Validate(e)
}
}
#[derive(Debug)]
pub struct ShaderInfo {
pub source: String,