nox_spirv/reflect/
error.rs1use std::ffi::CString;
2
3use core::{
4 ffi::FromBytesWithNulError,
5 fmt::{Display, self},
6 error::Error,
7};
8
9use crate::{op, ParseError, Literal};
10use super::*;
11
12#[derive(Debug)]
14pub enum ReflectError {
15 FromBytesWithNulError(FromBytesWithNulError),
19 EntryPointNotFound(CString, op::ExecutionModel),
21 EntryPointNotSet,
25 Parse(ParseError),
27 InvalidTypeId(Id),
29 InvalidConstantId(Id),
31 NonIntegerLiteral(Literal),
34 ExpectedConstantLiteral {
39 found: String
41 },
42 ExpectedScalarType {
45 found: op::Code,
49 },
50 ExpectedVectorType {
53 found: op::Code,
57 },
58 MissingRequiredDecoration(&'static str),
60 InvalidRuntimeArray,
62}
63
64impl Display for ReflectError {
65
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 match self {
68 Self::FromBytesWithNulError(_) => write!(f, "ffi string conversion error"),
69 Self::EntryPointNotFound(name, model) =>
70 write!(f, "entry point with name {name:?} and execution model {model} not found"),
71 Self::EntryPointNotSet => write!(f, "entry point not set"),
72 Self::Parse(_) => write!(f, "invalid spirv"),
73 Self::InvalidTypeId(id) => write!(f, "invalid type id {id}"),
74 Self::InvalidConstantId(id) => write!(f, "invalid constant id {id}"),
75 Self::NonIntegerLiteral(literal) => write!(f, "non-integer litral {literal:?}"),
76 Self::ExpectedConstantLiteral { found } => write!(f, "expected literal constant, found {found}"),
77 Self::ExpectedScalarType { found } => write!(f, "expected scalar type, found {found}"),
78 Self::ExpectedVectorType { found } => write!(f, "expected vector type, found {found}"),
79 Self::MissingRequiredDecoration(dec) => write!(f, "missing required decoration {dec}"),
80 Self::InvalidRuntimeArray
81 => write!(f, "invalid runtime array, runtime arrays must be the last member of a struct")
82 }
83 }
84}
85
86impl From<FromBytesWithNulError> for ReflectError {
87
88 #[inline]
89 fn from(value: FromBytesWithNulError) -> Self {
90 Self::FromBytesWithNulError(value)
91 }
92}
93
94impl From<ParseError> for ReflectError {
95
96 #[inline]
97 fn from(value: ParseError) -> Self {
98 Self::Parse(value)
99 }
100}
101
102impl Error for ReflectError {
103
104 fn source(&self) -> Option<&(dyn Error + 'static)> {
105 match self {
106 Self::FromBytesWithNulError(err) => Some(err),
107 Self::Parse(err) => Some(err),
108 _ => None,
109 }
110 }
111}
112
113pub type ReflectResult<T> = Result<T, ReflectError>;