fn invalid_variant_case(&self, enum_name: &str, result: &mut StreamBuilder) -> Result {
        // we'll be generating:
        // variant => Err(
        //    bincode::error::DecodeError::UnexpectedVariant {
        //        found: variant,
        //        type_name: <enum_name>
        //        allowed: ...,
        //    }
        // )
        //
        // Where allowed is either:
        // - bincode::error::AllowedEnumVariants::Range { min: 0, max: <max> }
        //   if we have no fixed value variants
        // - bincode::error::AllowedEnumVariants::Allowed(&[<variant1>, <variant2>, ...])
        //   if we have fixed value variants
        result.ident_str("variant");
        result.puncts("=>");
        result.ident_str("Err");
        result.group(Delimiter::Parenthesis, |err_inner| {
            err_inner.push_parsed("bincode::error::DecodeError::UnexpectedVariant")?;
            err_inner.group(Delimiter::Brace, |variant_inner| {
                variant_inner.ident_str("found");
                variant_inner.punct(':');
                variant_inner.ident_str("variant");
                variant_inner.punct(',');

                variant_inner.ident_str("type_name");
                variant_inner.punct(':');
                variant_inner.lit_str(enum_name);
                variant_inner.punct(',');

                variant_inner.ident_str("allowed");
                variant_inner.punct(':');

                if self.variants.iter().any(|i| i.has_fixed_value()) {
                    // we have fixed values, implement AllowedEnumVariants::Allowed
                    variant_inner.push_parsed("bincode::error::AllowedEnumVariants::Allowed")?;
                    variant_inner.group(Delimiter::Parenthesis, |allowed_inner| {
                        allowed_inner.punct('&');
                        allowed_inner.group(Delimiter::Bracket, |allowed_slice| {
                            for (idx, (ident, _)) in self.iter_fields().enumerate() {
                                if idx != 0 {
                                    allowed_slice.punct(',');
                                }
                                allowed_slice.extend(ident);
                            }
                            Ok(())
                        })?;
                        Ok(())
                    })?;
                } else {
                    // no fixed values, implement a range
                    variant_inner.push_parsed(format!(
                        "bincode::error::AllowedEnumVariants::Range {{ min: 0, max: {} }}",
                        self.variants.len() - 1
                    ))?;
                }
                Ok(())
            })?;
            Ok(())
        })?;
        Ok(())
    }
/// Build the catch-all case for an int-to-enum decode implementation
Build the catch-all case for an int-to-enum decode implementation
Build the catch - all case for an int - to - enum decode implementation
fn invalid_variant_case(&self, enum_name: &str, result: &mut StreamBuilder) -> Result {
        // we'll be generating:
        // variant => Err(
        //    bincode::error::DecodeError::UnexpectedVariant {
        //        found: variant,
        //        type_name: <enum_name>
        //        allowed: ...,
        //    }
        // )
        //
        // Where allowed is either:
        // - bincode::error::AllowedEnumVariants::Range { min: 0, max: <max> }
        //   if we have no fixed value variants
        // - bincode::error::AllowedEnumVariants::Allowed(&[<variant1>, <variant2>, ...])
        //   if we have fixed value variants
        result.ident_str("variant");
        result.puncts("=>");
        result.ident_str("Err");
        result.group(Delimiter::Parenthesis, |err_inner| {
            err_inner.push_parsed("bincode::error::DecodeError::UnexpectedVariant")?;
            err_inner.group(Delimiter::Brace, |variant_inner| {
                variant_inner.ident_str("found");
                variant_inner.punct(':');
                variant_inner.ident_str("variant");
                variant_inner.punct(',');
                variant_inner.ident_str("type_name");
                variant_inner.punct(':');
                variant_inner.lit_str(enum_name);
                variant_inner.punct(',');
                variant_inner.ident_str("allowed");
                variant_inner.punct(':');
                if self.variants.iter().any(|i| i.has_fixed_value()) {
                    // we have fixed values, implement AllowedEnumVariants::Allowed
                    variant_inner.push_parsed("bincode::error::AllowedEnumVariants::Allowed")?;
                    variant_inner.group(Delimiter::Parenthesis, |allowed_inner| {
                        allowed_inner.punct('&');
                        allowed_inner.group(Delimiter::Bracket, |allowed_slice| {
                            for (idx, (ident, _)) in self.iter_fields().enumerate() {
                                if idx != 0 {
                                    allowed_slice.punct(',');
                                }
                                allowed_slice.extend(ident);
                            }
                            Ok(())
                        })?;
                        Ok(())
                    })?;
                } else {
                    // no fixed values, implement a range
                    variant_inner.push_parsed(format!(
                        "bincode::error::AllowedEnumVariants::Range {{ min: 0, max: {} }}",
                        self.variants.len() - 1
                    ))?;
                }
                Ok(())
            })?;
            Ok(())
        })?;
        Ok(())
    }
fn invalid_variant_case ( & self , enum_name : & str , result : & mut StreamBuilder ) -> Result { // we'll be generating: // variant => Err( //    bincode::error::DecodeError::UnexpectedVariant { //        found: variant, //        type_name: <enum_name> //        allowed: ..., //    } // ) // // Where allowed is either: // - bincode::error::AllowedEnumVariants::Range { min: 0, max: <max> } //   if we have no fixed value variants // - bincode::error::AllowedEnumVariants::Allowed(&[<variant1>, <variant2>, ...]) //   if we have fixed value variants result . ident_str ( " " ) ; result . puncts ( " " ) ; result . ident_str ( " " ) ; result . group ( Delimiter :: Parenthesis , | err_inner | { err_inner . push_parsed ( " " ) ? ; err_inner . group ( Delimiter :: Brace , | variant_inner | { variant_inner . ident_str ( " " ) ; variant_inner . punct ( ':' ) ; variant_inner . ident_str ( " " ) ; variant_inner . punct ( ',' ) ; variant_inner . ident_str ( " " ) ; variant_inner . punct ( ':' ) ; variant_inner . lit_str ( enum_name ) ; variant_inner . punct ( ',' ) ; variant_inner . ident_str ( " " ) ; variant_inner . punct ( ':' ) ; if self . variants . iter ( ) . any ( | i | i . has_fixed_value ( ) ) { // we have fixed values, implement AllowedEnumVariants::Allowed variant_inner . push_parsed ( " " ) ? ; variant_inner . group ( Delimiter :: Parenthesis , | allowed_inner | { allowed_inner . punct ( '&' ) ; allowed_inner . group ( Delimiter :: Bracket , | allowed_slice | { for ( idx , ( ident , _ ) ) in self . iter_fields ( ) . enumerate ( ) { if idx != 0 { allowed_slice . punct ( ',' ) ; } allowed_slice . extend ( ident ) ; } Ok ( ( ) ) } ) ? ; Ok ( ( ) ) } ) ? ; } else { // no fixed values, implement a range variant_inner . push_parsed ( format ! ( " " self variants len ( ) 1 ) ) ? ; } Ok ( ( ) ) } ) ? ; Ok ( ( ) ) } ) ? ; Ok ( ( ) ) }
Build the catch-all case for an int-to-enum decode implementation
Build the catch - all case for an int - to - enum decode implementation
&self
enum_name
&str
result
&mut StreamBuilder