fn push_variant(&mut self, variant: &Variant) -> Result<()> {
        if self.used_variant_names.contains(&variant.ident.to_string()) {
            error(variant.span(), "Duplicated variant name.")
        } else if let Fields::Unit = variant.fields {
            // Parse the discriminant.
            if let Some((_, expr)) = &variant.discriminant {
                let discriminant_fail_message = format!(
                    "Enum set discriminants must be `u32`s.{}",
                    if self.has_signed_repr || self.has_large_repr {
                        format!(
                            " ({} discrimiants are still unsupported with reprs that allow them.)",
                            if self.has_large_repr {
                                "larger"
                            } else if self.has_signed_repr {
                                "negative"
                            } else {
                                "larger or negative"
                            }
                        )
                    } else {
                        String::new()
                    },
                );
                if let Expr::Lit(ExprLit { lit: Lit::Int(i), .. }) = expr {
                    match i.base10_parse() {
                        Ok(val) => self.cur_discrim = val,
                        Err(_) => error(expr.span(), &discriminant_fail_message)?,
                    }
                } else {
                    error(variant.span(), &discriminant_fail_message)?;
                }
            }

            // Validate the discriminant.
            let discriminant = self.cur_discrim;
            if discriminant >= 128 {
                let message = if self.variants.len() <= 127 {
                    "`#[derive(EnumSetType)]` currently only supports discriminants up to 127."
                } else {
                    "`#[derive(EnumSetType)]` currently only supports enums up to 128 variants."
                };
                error(variant.span(), message)?;
            }
            if self.used_discriminants.contains(&discriminant) {
                error(variant.span(), "Duplicated enum discriminant.")?;
            }

            // Add the variant to the info.
            self.cur_discrim += 1;
            if discriminant > self.max_discrim {
                self.max_discrim = discriminant;
            }
            self.variants.push(EnumSetValue {
                name: variant.ident.clone(),
                variant_repr: discriminant,
            });
            self.used_variant_names.insert(variant.ident.to_string());
            self.used_discriminants.insert(discriminant);

            Ok(())
        } else {
            error(variant.span(), "`#[derive(EnumSetType)]` can only be used on fieldless enums.")
        }
    }
/// Adds a variant to the enumset.
Adds a variant to the enumset.
Adds a variant to the enumset .
fn push_variant(&mut self, variant: &Variant) -> Result<()> {
        if self.used_variant_names.contains(&variant.ident.to_string()) {
            error(variant.span(), "Duplicated variant name.")
        } else if let Fields::Unit = variant.fields {
            // Parse the discriminant.
            if let Some((_, expr)) = &variant.discriminant {
                let discriminant_fail_message = format!(
                    "Enum set discriminants must be `u32`s.{}",
                    if self.has_signed_repr || self.has_large_repr {
                        format!(
                            " ({} discrimiants are still unsupported with reprs that allow them.)",
                            if self.has_large_repr {
                                "larger"
                            } else if self.has_signed_repr {
                                "negative"
                            } else {
                                "larger or negative"
                            }
                        )
                    } else {
                        String::new()
                    },
                );
                if let Expr::Lit(ExprLit { lit: Lit::Int(i), .. }) = expr {
                    match i.base10_parse() {
                        Ok(val) => self.cur_discrim = val,
                        Err(_) => error(expr.span(), &discriminant_fail_message)?,
                    }
                } else {
                    error(variant.span(), &discriminant_fail_message)?;
                }
            }
            // Validate the discriminant.
            let discriminant = self.cur_discrim;
            if discriminant >= 128 {
                let message = if self.variants.len() <= 127 {
                    "`#[derive(EnumSetType)]` currently only supports discriminants up to 127."
                } else {
                    "`#[derive(EnumSetType)]` currently only supports enums up to 128 variants."
                };
                error(variant.span(), message)?;
            }
            if self.used_discriminants.contains(&discriminant) {
                error(variant.span(), "Duplicated enum discriminant.")?;
            }
            // Add the variant to the info.
            self.cur_discrim += 1;
            if discriminant > self.max_discrim {
                self.max_discrim = discriminant;
            }
            self.variants.push(EnumSetValue {
                name: variant.ident.clone(),
                variant_repr: discriminant,
            });
            self.used_variant_names.insert(variant.ident.to_string());
            self.used_discriminants.insert(discriminant);
            Ok(())
        } else {
            error(variant.span(), "`#[derive(EnumSetType)]` can only be used on fieldless enums.")
        }
    }
fn push_variant ( & mut self , variant : & Variant ) -> Result < ( ) > { if self . used_variant_names . contains ( & variant . ident . to_string ( ) ) { error ( variant . span ( ) , " " ) } else if let Fields :: Unit = variant . fields { // Parse the discriminant. if let Some ( ( _ , expr ) ) = & variant . discriminant { let discriminant_fail_message = format ! ( " " if self has_signed_repr self has_large_repr { format ( " " if self has_large_repr { " " } else if self has_signed_repr { " " } else { " " } ) } else { String new ( ) } ) ; if let Expr :: Lit ( ExprLit { lit : Lit :: Int ( i ) , .. } ) = expr { match i . base10_parse ( ) { Ok ( val ) => self . cur_discrim = val , Err ( _ ) => error ( expr . span ( ) , & discriminant_fail_message ) ? , } } else { error ( variant . span ( ) , & discriminant_fail_message ) ? ; } } // Validate the discriminant. let discriminant = self . cur_discrim ; if discriminant >= 128 { let message = if self . variants . len ( ) <= 127 { " " } else { " " } ; error ( variant . span ( ) , message ) ? ; } if self . used_discriminants . contains ( & discriminant ) { error ( variant . span ( ) , " " ) ? ; } // Add the variant to the info. self . cur_discrim += 1 ; if discriminant > self . max_discrim { self . max_discrim = discriminant ; } self . variants . push ( EnumSetValue { name : variant . ident . clone ( ) , variant_repr : discriminant , } ) ; self . used_variant_names . insert ( variant . ident . to_string ( ) ) ; self . used_discriminants . insert ( discriminant ) ; Ok ( ( ) ) } else { error ( variant . span ( ) , " " ) } }
Adds a variant to the enumset.
Adds a variant to the enumset .
&mut self
variant
&Variant
&mut self
variant
&Variant