pub fn impl_saveload(ast: &mut DeriveInput) -> TokenStream {
    use syn::Data;

    add_where_clauses(
        &mut ast.generics.where_clause,
        &ast.generics.params,
        |ty| parse_quote!(#ty: ConvertSaveload<MA, Error = std::convert::Infallible> + ConvertSaveload<MA, Error = std::convert::Infallible>),
    );
    add_where_clauses(
        &mut ast.generics.where_clause,
        &ast.generics.params,
        |ty| parse_quote!(<#ty as ConvertSaveload<MA>>::Data: ::serde::Serialize + ::serde::de::DeserializeOwned + Clone),
    );
    add_where_clauses(
        &mut ast.generics.where_clause,
        &ast.generics.params,
        |ty| parse_quote!(<#ty as ConvertSaveload<MA>>::Data: ::serde::Serialize + ::serde::de::DeserializeOwned + Clone),
    );
    add_where_clause(
        &mut ast.generics.where_clause,
        parse_quote!(MA: ::serde::Serialize + ::serde::de::DeserializeOwned + Marker),
    );
    add_where_clause(
        &mut ast.generics.where_clause,
        parse_quote!(for <'deser> MA: ::serde::Deserialize<'deser>),
    );

    let derive = match ast.data {
        Data::Struct(ref mut data) => saveload_struct(data, &mut ast.ident, &mut ast.generics),
        Data::Enum(ref data) => saveload_enum(data, &ast.ident, &ast.generics),
        Data::Union(_) => panic!("Unions cannot derive `ConvertSaveload`"),
    };

    let name = &ast.ident;

    let mut impl_generics = ast.generics.clone();
    impl_generics.params.push(parse_quote!(MA));
    let (impl_generics, saveload_ty_generics, where_clause) = impl_generics.split_for_impl();
    // We don't want the type generics we just made because they have MA which our
    // normal type doesn't have
    let (_, ty_generics, _) = ast.generics.split_for_impl();

    let type_def = derive.type_def;
    let saveload_name = derive.saveload_name;

    let ser = derive.ser;
    let de = derive.de;

    let tt = quote! {
        #[derive(Serialize, Deserialize, Clone)]
        #[serde(bound = "MA: Marker")]
        pub #type_def

        impl #impl_generics ConvertSaveload<MA> for #name #ty_generics #where_clause {
            type Data = #saveload_name #saveload_ty_generics;
            type Error = std::convert::Infallible;

            fn convert_into<F>(&self, mut ids: F) -> Result<Self::Data, Self::Error>
            where
                F: FnMut(Entity) -> Option<MA>
            {
                #ser
            }

            fn convert_from<F>(data: Self::Data, mut ids: F) -> Result<Self, Self::Error>
            where
                F: FnMut(MA) -> Option<Entity>
            {
                #de
            }
        }
    };

    // panic!("{}", tt);

    tt
}
/// The main entrypoint, sets things up and delegates to the
/// type we're deriving on.
The main entrypoint, sets things up and delegates to the
type we're deriving on.
The main entrypoint sets things up and delegates to the type we ' re deriving on .
pub fn impl_saveload(ast: &mut DeriveInput) -> TokenStream {
    use syn::Data;
    add_where_clauses(
        &mut ast.generics.where_clause,
        &ast.generics.params,
        |ty| parse_quote!(#ty: ConvertSaveload<MA, Error = std::convert::Infallible> + ConvertSaveload<MA, Error = std::convert::Infallible>),
    );
    add_where_clauses(
        &mut ast.generics.where_clause,
        &ast.generics.params,
        |ty| parse_quote!(<#ty as ConvertSaveload<MA>>::Data: ::serde::Serialize + ::serde::de::DeserializeOwned + Clone),
    );
    add_where_clauses(
        &mut ast.generics.where_clause,
        &ast.generics.params,
        |ty| parse_quote!(<#ty as ConvertSaveload<MA>>::Data: ::serde::Serialize + ::serde::de::DeserializeOwned + Clone),
    );
    add_where_clause(
        &mut ast.generics.where_clause,
        parse_quote!(MA: ::serde::Serialize + ::serde::de::DeserializeOwned + Marker),
    );
    add_where_clause(
        &mut ast.generics.where_clause,
        parse_quote!(for <'deser> MA: ::serde::Deserialize<'deser>),
    );
    let derive = match ast.data {
        Data::Struct(ref mut data) => saveload_struct(data, &mut ast.ident, &mut ast.generics),
        Data::Enum(ref data) => saveload_enum(data, &ast.ident, &ast.generics),
        Data::Union(_) => panic!("Unions cannot derive `ConvertSaveload`"),
    };
    let name = &ast.ident;
    let mut impl_generics = ast.generics.clone();
    impl_generics.params.push(parse_quote!(MA));
    let (impl_generics, saveload_ty_generics, where_clause) = impl_generics.split_for_impl();
    // We don't want the type generics we just made because they have MA which our
    // normal type doesn't have
    let (_, ty_generics, _) = ast.generics.split_for_impl();
    let type_def = derive.type_def;
    let saveload_name = derive.saveload_name;
    let ser = derive.ser;
    let de = derive.de;
    let tt = quote! {
        #[derive(Serialize, Deserialize, Clone)]
        #[serde(bound = "MA: Marker")]
        pub #type_def
        impl #impl_generics ConvertSaveload<MA> for #name #ty_generics #where_clause {
            type Data = #saveload_name #saveload_ty_generics;
            type Error = std::convert::Infallible;
            fn convert_into<F>(&self, mut ids: F) -> Result<Self::Data, Self::Error>
            where
                F: FnMut(Entity) -> Option<MA>
            {
                #ser
            }
            fn convert_from<F>(data: Self::Data, mut ids: F) -> Result<Self, Self::Error>
            where
                F: FnMut(MA) -> Option<Entity>
            {
                #de
            }
        }
    };
    // panic!("{}", tt);
    tt
}
pub fn impl_saveload ( ast : & mut DeriveInput ) -> TokenStream { use syn :: Data ; add_where_clauses ( & mut ast . generics . where_clause , & ast . generics . params , | ty | parse_quote ! ( ty ConvertSaveload MA Error std convert Infallible ConvertSaveload MA Error std convert Infallible ) , ) ; add_where_clauses ( & mut ast . generics . where_clause , & ast . generics . params , | ty | parse_quote ! ( ty as ConvertSaveload MA Data serde Serialize serde de DeserializeOwned Clone ) , ) ; add_where_clauses ( & mut ast . generics . where_clause , & ast . generics . params , | ty | parse_quote ! ( ty as ConvertSaveload MA Data serde Serialize serde de DeserializeOwned Clone ) , ) ; add_where_clause ( & mut ast . generics . where_clause , parse_quote ! ( MA serde Serialize serde de DeserializeOwned Marker ) , ) ; add_where_clause ( & mut ast . generics . where_clause , parse_quote ! ( for ' deser MA serde Deserialize ' deser ) , ) ; let derive = match ast . data { Data :: Struct ( ref mut data ) => saveload_struct ( data , & mut ast . ident , & mut ast . generics ) , Data :: Enum ( ref data ) => saveload_enum ( data , & ast . ident , & ast . generics ) , Data :: Union ( _ ) => panic ! ( " " ) , } ; let name = & ast . ident ; let mut impl_generics = ast . generics . clone ( ) ; impl_generics . params . push ( parse_quote ! ( MA ) ) ; let ( impl_generics , saveload_ty_generics , where_clause ) = impl_generics . split_for_impl ( ) ; // We don't want the type generics we just made because they have MA which our // normal type doesn't have let ( _ , ty_generics , _ ) = ast . generics . split_for_impl ( ) ; let type_def = derive . type_def ; let saveload_name = derive . saveload_name ; let ser = derive . ser ; let de = derive . de ; let tt = quote ! { [ derive ( Serialize Deserialize Clone ) ] [ serde ( bound " " ) ] pub type_def impl impl_generics ConvertSaveload MA for name ty_generics where_clause { type Data saveload_name saveload_ty_generics type Error std convert Infallible fn convert_into F ( self mut ids F ) Result Self Data Self Error where F FnMut ( Entity ) Option MA { ser } fn convert_from F ( data Self Data mut ids F ) Result Self Self Error where F FnMut ( MA ) Option Entity { de } } } ; // panic!("{}", tt); tt }
The main entrypoint, sets things up and delegates to the
type we're deriving on.
The main entrypoint sets things up and delegates to the type we ' re deriving on .
ast
&mut DeriveInput