fn build(&self) -> TokenStream {
        let mut var_extracts = Vec::new();
        let mut error_names = String::new();
        for (i, var) in self.variants.iter().enumerate() {
            let struct_derive = var.build();
            let ext = quote!(
                let maybe_ret = || -> pyo3::PyResult<Self> {
                    #struct_derive
                }();

                match maybe_ret {
                    ok @ Ok(_) => return ok,
                    Err(inner) => {
                        let py = pyo3::PyNativeType::py(obj);
                        err_reasons.push_str(&format!("{}\n", inner.instance(py).str().unwrap()));
                    }
                }
            );

            var_extracts.push(ext);
            error_names.push_str(&var.err_name);
            if i < self.variants.len() - 1 {
                error_names.push_str(", ");
            }
        }
        let error_names = if self.variants.len() > 1 {
            format!("Union[{}]", error_names)
        } else {
            error_names
        };
        let ty_name = self.enum_ident.to_string();
        quote!(
            let mut err_reasons = String::new();
            #(#var_extracts)*
            let err_msg = format!("failed to extract enum {} ('{}')\n{}",
                #ty_name,
                #error_names,
                &err_reasons);
            Err(pyo3::exceptions::PyTypeError::new_err(err_msg))
        )
    }
/// Build derivation body for enums.
Build derivation body for enums.
Build derivation body for enums .
fn build(&self) -> TokenStream {
        let mut var_extracts = Vec::new();
        let mut error_names = String::new();
        for (i, var) in self.variants.iter().enumerate() {
            let struct_derive = var.build();
            let ext = quote!(
                let maybe_ret = || -> pyo3::PyResult<Self> {
                    #struct_derive
                }();
                match maybe_ret {
                    ok @ Ok(_) => return ok,
                    Err(inner) => {
                        let py = pyo3::PyNativeType::py(obj);
                        err_reasons.push_str(&format!("{}\n", inner.instance(py).str().unwrap()));
                    }
                }
            );
            var_extracts.push(ext);
            error_names.push_str(&var.err_name);
            if i < self.variants.len() - 1 {
                error_names.push_str(", ");
            }
        }
        let error_names = if self.variants.len() > 1 {
            format!("Union[{}]", error_names)
        } else {
            error_names
        };
        let ty_name = self.enum_ident.to_string();
        quote!(
            let mut err_reasons = String::new();
            #(#var_extracts)*
            let err_msg = format!("failed to extract enum {} ('{}')\n{}",
                #ty_name,
                #error_names,
                &err_reasons);
            Err(pyo3::exceptions::PyTypeError::new_err(err_msg))
        )
    }
fn build ( & self ) -> TokenStream { let mut var_extracts = Vec :: new ( ) ; let mut error_names = String :: new ( ) ; for ( i , var ) in self . variants . iter ( ) . enumerate ( ) { let struct_derive = var . build ( ) ; let ext = quote ! ( let maybe_ret pyo3 PyResult Self { struct_derive } ( ) match maybe_ret { ok Ok ( ) return ok Err ( inner ) { let py pyo3 PyNativeType py ( obj ) err_reasons push_str ( format ( " \n " inner instance ( py ) str ( ) unwrap ( ) ) ) } } ) ; var_extracts . push ( ext ) ; error_names . push_str ( & var . err_name ) ; if i < self . variants . len ( ) - 1 { error_names . push_str ( " " ) ; } } let error_names = if self . variants . len ( ) > 1 { format ! ( " " error_names ) } else { error_names } ; let ty_name = self . enum_ident . to_string ( ) ; quote ! ( let mut err_reasons String new ( ) ( var_extracts ) let err_msg format ( " \n " ty_name error_names err_reasons ) Err ( pyo3 exceptions PyTypeError new_err ( err_msg ) ) ) }
Build derivation body for enums.
Build derivation body for enums .
&self
&self