pub fn generate(class: &Class) -> TokenStream {
    let name = &class.name;
    let vis = &class.visibility;

    let parameters = &class.fields;
    let user_fields = class.fields.iter().map(|f| {
        let name = &f.ident;
        quote! {
            #name
        }
    });

    let interface_inits = gen_vpointer_inits(class);
    let ref_count_ident = crate::utils::ref_count_ident();

    let interfaces = &class.interfaces;
    let interface_fields = gen_allocate_interface_fields(interfaces);

    quote! {
        /// Allocate the class casting it to the supplied interface
        ///
        /// This allocates the class on the heap and pins it. This is because COM classes
        /// must have a stable location in memory. Once a COM class is instantiated somewhere
        /// it must stay there.
        #vis fn allocate(#(#parameters),*) -> ::com::production::ClassAllocation<Self> {
            #interface_inits
            let instance = #name {
                #interface_fields
                #ref_count_ident: ::core::cell::Cell::new(1),
                #(#user_fields),*
            };
            let instance = ::com::alloc::boxed::Box::pin(instance);
            ::com::production::ClassAllocation::new(instance)
        }
    }
}
/// Generates a function used to instantiate the COM class
Generates a function used to instantiate the COM class
Generates a function used to instantiate the COM class
pub fn generate(class: &Class) -> TokenStream {
    let name = &class.name;
    let vis = &class.visibility;
    let parameters = &class.fields;
    let user_fields = class.fields.iter().map(|f| {
        let name = &f.ident;
        quote! {
            #name
        }
    });
    let interface_inits = gen_vpointer_inits(class);
    let ref_count_ident = crate::utils::ref_count_ident();
    let interfaces = &class.interfaces;
    let interface_fields = gen_allocate_interface_fields(interfaces);
    quote! {
        /// Allocate the class casting it to the supplied interface
        ///
        /// This allocates the class on the heap and pins it. This is because COM classes
        /// must have a stable location in memory. Once a COM class is instantiated somewhere
        /// it must stay there.
        #vis fn allocate(#(#parameters),*) -> ::com::production::ClassAllocation<Self> {
            #interface_inits
            let instance = #name {
                #interface_fields
                #ref_count_ident: ::core::cell::Cell::new(1),
                #(#user_fields),*
            };
            let instance = ::com::alloc::boxed::Box::pin(instance);
            ::com::production::ClassAllocation::new(instance)
        }
    }
}
pub fn generate ( class : & Class ) -> TokenStream { let name = & class . name ; let vis = & class . visibility ; let parameters = & class . fields ; let user_fields = class . fields . iter ( ) . map ( | f | { let name = & f . ident ; quote ! { name } } ) ; let interface_inits = gen_vpointer_inits ( class ) ; let ref_count_ident = crate :: utils :: ref_count_ident ( ) ; let interfaces = & class . interfaces ; let interface_fields = gen_allocate_interface_fields ( interfaces ) ; quote ! { /// Allocate the class casting it to the supplied interface /// This allocates the class on the heap and pins it. This is because COM classes /// must have a stable location in memory. Once a COM class is instantiated somewhere /// it must stay there. vis fn allocate ( ( parameters ) ) com production ClassAllocation Self { interface_inits let instance name { interface_fields ref_count_ident core cell Cell new ( 1 ) ( user_fields ) } let instance com alloc boxed Box pin ( instance ) com production ClassAllocation new ( instance ) } } }
Generates a function used to instantiate the COM class
Generates a function used to instantiate the COM class
class
&Class
class
&Class