pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result<TokenStream> {
    let mut trait_generics = tokens.generics.clone();
    let generics = &tokens.generics;
    let lt_param = if let Some(lt) = verify_and_get_lifetime(generics)? {
        lt.clone()
    } else {
        trait_generics.params.push(parse_quote!('source));
        parse_quote!('source)
    };
    let mut where_clause: syn::WhereClause = parse_quote!(where);
    for param in generics.type_params() {
        let gen_ident = &param.ident;
        where_clause
            .predicates
            .push(parse_quote!(#gen_ident: FromPyObject<#lt_param>))
    }
    let derives = match &tokens.data {
        syn::Data::Enum(en) => {
            let en = Enum::new(en, &tokens.ident)?;
            en.build()
        }
        syn::Data::Struct(st) => {
            let options = ContainerOptions::from_attrs(&tokens.attrs)?;
            if let Some(lit_str) = &options.annotation {
                bail_spanned!(lit_str.span() => "`annotation` is unsupported for structs");
            }
            let ident = &tokens.ident;
            let st = Container::new(&st.fields, parse_quote!(#ident), options, false)?;
            st.build()
        }
        syn::Data::Union(_) => bail_spanned!(
            tokens.span() => "#[derive(FromPyObject)] is not supported for unions"
        ),
    };

    let ident = &tokens.ident;
    Ok(quote!(
        #[automatically_derived]
        impl#trait_generics pyo3::FromPyObject<#lt_param> for #ident#generics #where_clause {
            fn extract(obj: &#lt_param pyo3::PyAny) -> pyo3::PyResult<Self>  {
                #derives
            }
        }
    ))
}
/// Derive FromPyObject for enums and structs.
///
///   * Max 1 lifetime specifier, will be tied to `FromPyObject`'s specifier
///   * At least one field, in case of `#[transparent]`, exactly one field
///   * At least one variant for enums.
///   * Fields of input structs and enums must implement `FromPyObject` or be annotated with `from_py_with`
///   * Derivation for structs with generic fields like `struct<T> Foo(T)`
///     adds `T: FromPyObject` on the derived implementation.
Derive FromPyObject for enums and structs.
Max 1 lifetime specifier, will be tied to `FromPyObject`'s specifier
At least one field, in case of `#[transparent]`, exactly one field
At least one variant for enums.
Derive FromPyObject for enums and structs . Max 1 lifetime specifier will be tied to ` FromPyObject ` ' s specifier At least one field in case of ` # [ transparent ] ` exactly one field At least one variant for enums .
pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result<TokenStream> {
    let mut trait_generics = tokens.generics.clone();
    let generics = &tokens.generics;
    let lt_param = if let Some(lt) = verify_and_get_lifetime(generics)? {
        lt.clone()
    } else {
        trait_generics.params.push(parse_quote!('source));
        parse_quote!('source)
    };
    let mut where_clause: syn::WhereClause = parse_quote!(where);
    for param in generics.type_params() {
        let gen_ident = &param.ident;
        where_clause
            .predicates
            .push(parse_quote!(#gen_ident: FromPyObject<#lt_param>))
    }
    let derives = match &tokens.data {
        syn::Data::Enum(en) => {
            let en = Enum::new(en, &tokens.ident)?;
            en.build()
        }
        syn::Data::Struct(st) => {
            let options = ContainerOptions::from_attrs(&tokens.attrs)?;
            if let Some(lit_str) = &options.annotation {
                bail_spanned!(lit_str.span() => "`annotation` is unsupported for structs");
            }
            let ident = &tokens.ident;
            let st = Container::new(&st.fields, parse_quote!(#ident), options, false)?;
            st.build()
        }
        syn::Data::Union(_) => bail_spanned!(
            tokens.span() => "#[derive(FromPyObject)] is not supported for unions"
        ),
    };
    let ident = &tokens.ident;
    Ok(quote!(
        #[automatically_derived]
        impl#trait_generics pyo3::FromPyObject<#lt_param> for #ident#generics #where_clause {
            fn extract(obj: &#lt_param pyo3::PyAny) -> pyo3::PyResult<Self>  {
                #derives
            }
        }
    ))
}
pub fn build_derive_from_pyobject ( tokens : & DeriveInput ) -> Result < TokenStream > { let mut trait_generics = tokens . generics . clone ( ) ; let generics = & tokens . generics ; let lt_param = if let Some ( lt ) = verify_and_get_lifetime ( generics ) ? { lt . clone ( ) } else { trait_generics . params . push ( parse_quote ! ( ' source ) ) ; parse_quote ! ( ' source ) } ; let mut where_clause : syn :: WhereClause = parse_quote ! ( where ) ; for param in generics . type_params ( ) { let gen_ident = & param . ident ; where_clause . predicates . push ( parse_quote ! ( gen_ident FromPyObject lt_param ) ) } let derives = match & tokens . data { syn :: Data :: Enum ( en ) => { let en = Enum :: new ( en , & tokens . ident ) ? ; en . build ( ) } syn :: Data :: Struct ( st ) => { let options = ContainerOptions :: from_attrs ( & tokens . attrs ) ? ; if let Some ( lit_str ) = & options . annotation { bail_spanned ! ( lit_str span ( ) " " ) ; } let ident = & tokens . ident ; let st = Container :: new ( & st . fields , parse_quote ! ( ident ) , options , false ) ? ; st . build ( ) } syn :: Data :: Union ( _ ) => bail_spanned ! ( tokens span ( ) " " ) , } ; let ident = & tokens . ident ; Ok ( quote ! ( [ automatically_derived ] impl trait_generics pyo3 FromPyObject lt_param for ident generics where_clause { fn extract ( obj lt_param pyo3 PyAny ) pyo3 PyResult Self { derives } } ) ) }
Derive FromPyObject for enums and structs.
Derive FromPyObject for enums and structs .
tokens
&DeriveInput
tokens
&DeriveInput