pub fn gen_operand_decode_errors(grammar: &[structs::OperandKind]) -> TokenStream {
    let kinds: Vec<&str> = grammar
        .iter()
        .filter(|element| {
            !(element.kind.starts_with("Pair")
                || element.kind.starts_with("Id")
                || element.kind.starts_with("Literal"))
        })
        .map(|element| element.kind.as_str())
        .collect();

    let error_types = kinds.iter().map(|kind| {
        let error_name = as_ident(&format!("{}Unknown", kind));
        quote! { #error_name(usize, spirv::Word) }
    });

    let error_matches = kinds.iter().map(|kind| {
        let error_name = as_ident(&format!("{}Unknown", kind));
        let fmt_string = format!("unknown value {{}} for operand kind {} at index {{}}", kind);
        quote! {
            Error::#error_name(index, word) => write!(f, #fmt_string, word, index)
        }
    });

    quote! {
        use std::{error, fmt};

        #[doc = "Decoder Error"]
        #[derive(Debug, PartialEq)]
        #[allow(clippy::upper_case_acronyms)]
        pub enum Error {
            StreamExpected(usize),
            LimitReached(usize),
            #(#error_types),*,
            ///Failed to decode a string.
            ///
            ///For structured error handling, the second element could be
            ///`string::FromUtf8Error`, but the will prohibit the compiler
            ///from generating `PartialEq` for this enum.
            DecodeStringFailed(usize, String),
        }

        impl fmt::Display for Error {
            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                match *self {
                    Error::StreamExpected(index) => write!(f, "expected more bytes in the stream at index {}", index),
                    Error::LimitReached(index) => write!(f, "reached word limit at index {}", index),
                    #(#error_matches),*,
                    Error::DecodeStringFailed(index, ref e) => write!(f, "cannot decode string at index {}: {}", index, e),
                }
            }
        }

        impl error::Error for Error {}
    }
}
/// Returns the generated operand decoding errors for binary::Decoder by
/// walking the given SPIR-V operand kinds `grammar`.
Returns the generated operand decoding errors for binary::Decoder by
walking the given SPIR-V operand kinds `grammar`.
Returns the generated operand decoding errors for binary :: Decoder by walking the given SPIR - V operand kinds ` grammar ` .
pub fn gen_operand_decode_errors(grammar: &[structs::OperandKind]) -> TokenStream {
    let kinds: Vec<&str> = grammar
        .iter()
        .filter(|element| {
            !(element.kind.starts_with("Pair")
                || element.kind.starts_with("Id")
                || element.kind.starts_with("Literal"))
        })
        .map(|element| element.kind.as_str())
        .collect();
    let error_types = kinds.iter().map(|kind| {
        let error_name = as_ident(&format!("{}Unknown", kind));
        quote! { #error_name(usize, spirv::Word) }
    });
    let error_matches = kinds.iter().map(|kind| {
        let error_name = as_ident(&format!("{}Unknown", kind));
        let fmt_string = format!("unknown value {{}} for operand kind {} at index {{}}", kind);
        quote! {
            Error::#error_name(index, word) => write!(f, #fmt_string, word, index)
        }
    });
    quote! {
        use std::{error, fmt};
        #[doc = "Decoder Error"]
        #[derive(Debug, PartialEq)]
        #[allow(clippy::upper_case_acronyms)]
        pub enum Error {
            StreamExpected(usize),
            LimitReached(usize),
            #(#error_types),*,
            ///Failed to decode a string.
            ///
            ///For structured error handling, the second element could be
            ///`string::FromUtf8Error`, but the will prohibit the compiler
            ///from generating `PartialEq` for this enum.
            DecodeStringFailed(usize, String),
        }
        impl fmt::Display for Error {
            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                match *self {
                    Error::StreamExpected(index) => write!(f, "expected more bytes in the stream at index {}", index),
                    Error::LimitReached(index) => write!(f, "reached word limit at index {}", index),
                    #(#error_matches),*,
                    Error::DecodeStringFailed(index, ref e) => write!(f, "cannot decode string at index {}: {}", index, e),
                }
            }
        }
        impl error::Error for Error {}
    }
}
pub fn gen_operand_decode_errors ( grammar : & [ structs :: OperandKind ] ) -> TokenStream { let kinds : Vec < & str > = grammar . iter ( ) . filter ( | element | { ! ( element . kind . starts_with ( " " ) || element . kind . starts_with ( " " ) || element . kind . starts_with ( " " ) ) } ) . map ( | element | element . kind . as_str ( ) ) . collect ( ) ; let error_types = kinds . iter ( ) . map ( | kind | { let error_name = as_ident ( & format ! ( " " kind ) ) ; quote ! { error_name ( usize spirv Word ) } } ) ; let error_matches = kinds . iter ( ) . map ( | kind | { let error_name = as_ident ( & format ! ( " " kind ) ) ; let fmt_string = format ! ( " " kind ) ; quote ! { Error error_name ( index word ) write ( f fmt_string word index ) } } ) ; quote ! { use std { error fmt } [ doc " " ] [ derive ( Debug PartialEq ) ] [ allow ( clippy upper_case_acronyms ) ] pub enum Error { StreamExpected ( usize ) LimitReached ( usize ) ( error_types ) ///Failed to decode a string. ///For structured error handling, the second element could be ///`string::FromUtf8Error`, but the will prohibit the compiler ///from generating `PartialEq` for this enum. DecodeStringFailed ( usize String ) } impl fmt Display for Error { fn fmt ( self f mut fmt Formatter ) fmt Result { match self { Error StreamExpected ( index ) write ( f " " index ) Error LimitReached ( index ) write ( f " " index ) ( error_matches ) Error DecodeStringFailed ( index ref e ) write ( f " " index e ) } } } impl error Error for Error { } } }
Returns the generated operand decoding errors for binary::Decoder by
walking the given SPIR-V operand kinds `grammar`.
Returns the generated operand decoding errors for binary :: Decoder by walking the given SPIR - V operand kinds ` grammar ` .
grammar
&[structs::OperandKind]
grammar
&[structs::OperandKind]