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