fn rust_to_com_delegate(
    itf_variant : &model::ComInterfaceVariant,
    method_info : &ComMethodInfo,
    vtable_ident : &Ident,
) -> TokenStream {

    // The COM out-arguments that mirror the Rust return value will
    // require temporary variables during the COM call. Format their
    // declarations.
    let out_arg_declarations = method_info.returnhandler.com_out_args()
            .iter()
            .map( |ca| {
                let ident = &ca.name;
                let ty = &ca.handler.com_ty( Direction::Retval );
                let default = ca.handler.default_value();
                quote!( let mut #ident : #ty = #default; )
            } ).collect::<Vec<_>>();

    // Format the in and out parameters for the COM call.
    let ( temporaries, params ) : ( Vec<_>, Vec<_> ) = method_info.raw_com_args()
            .into_iter()
            .map( |com_arg| {
                let name = com_arg.name;
                match com_arg.dir {
                    Direction::In => {
                        let param = com_arg.handler.rust_to_com( &name, Direction::In );
                        ( param.temporary, param.value )
                    },
                    Direction::Out | Direction::Retval
                        => ( None, quote!( &mut #name ) ),
                }
            } )
            .unzip();

    // Combine the parameters into the final parameter list.
    // This includes the 'this' pointer and both the IN and OUT
    // parameters.
    let params = iter::once( quote!( comptr.ptr ) ).chain( params );

    // Create the return statement.
    let return_ident = Ident::new( "__result", Span::call_site() );
    let return_statement = method_info
            .returnhandler
            .com_to_rust_return( &return_ident );

    // Resolve some of the fields needed for quote.
    let method_ident = &method_info.unique_name;
    let return_ty = &method_info.rust_return_ty;
    let iid_tokens = utils::get_guid_tokens( itf_variant.iid() );

    // Construct the final method.
    quote!(
        let vtbl = comptr.ptr as *const *const #vtable_ident;

        #( #temporaries )*

        // Use an IIFE to act as a try/catch block. The various template
        // substitutions might end up using ?'s for error handling. The IIFE allows
        // us to handle the results here immediately.
        #[allow(unused_unsafe)]  // The fn itself _might_ be unsafe.
        let result : Result< #return_ty, ::intercom::ComError > = ( || unsafe {
            #( #out_arg_declarations )*;
            let #return_ident = ((**vtbl).#method_ident)( #( #params ),* );

            let INTERCOM_iid = #iid_tokens;
            Ok( { #return_statement } )
        } )();

        return match result {
            Ok( v ) => v,
            Err( err ) => < #return_ty as ::intercom::ErrorValue >::from_com_error( err ),
        };
    )
}
/// Creates the functions responsible for delegating calls from Rust to COM
/// interfaces.
///
/// # Arguments
///
/// * `itf_variant` - Interface variant details.
/// * `method_info` - Method to delegate.
/// * `vtable_ident` - Vtable to use for the delegation.
Creates the functions responsible for delegating calls from Rust to COM
interfaces.
Creates the functions responsible for delegating calls from Rust to COM interfaces .
fn rust_to_com_delegate(
    itf_variant : &model::ComInterfaceVariant,
    method_info : &ComMethodInfo,
    vtable_ident : &Ident,
) -> TokenStream {
    // The COM out-arguments that mirror the Rust return value will
    // require temporary variables during the COM call. Format their
    // declarations.
    let out_arg_declarations = method_info.returnhandler.com_out_args()
            .iter()
            .map( |ca| {
                let ident = &ca.name;
                let ty = &ca.handler.com_ty( Direction::Retval );
                let default = ca.handler.default_value();
                quote!( let mut #ident : #ty = #default; )
            } ).collect::<Vec<_>>();
    // Format the in and out parameters for the COM call.
    let ( temporaries, params ) : ( Vec<_>, Vec<_> ) = method_info.raw_com_args()
            .into_iter()
            .map( |com_arg| {
                let name = com_arg.name;
                match com_arg.dir {
                    Direction::In => {
                        let param = com_arg.handler.rust_to_com( &name, Direction::In );
                        ( param.temporary, param.value )
                    },
                    Direction::Out | Direction::Retval
                        => ( None, quote!( &mut #name ) ),
                }
            } )
            .unzip();
    // Combine the parameters into the final parameter list.
    // This includes the 'this' pointer and both the IN and OUT
    // parameters.
    let params = iter::once( quote!( comptr.ptr ) ).chain( params );
    // Create the return statement.
    let return_ident = Ident::new( "__result", Span::call_site() );
    let return_statement = method_info
            .returnhandler
            .com_to_rust_return( &return_ident );
    // Resolve some of the fields needed for quote.
    let method_ident = &method_info.unique_name;
    let return_ty = &method_info.rust_return_ty;
    let iid_tokens = utils::get_guid_tokens( itf_variant.iid() );
    // Construct the final method.
    quote!(
        let vtbl = comptr.ptr as *const *const #vtable_ident;
        #( #temporaries )*
        // Use an IIFE to act as a try/catch block. The various template
        // substitutions might end up using ?'s for error handling. The IIFE allows
        // us to handle the results here immediately.
        #[allow(unused_unsafe)]  // The fn itself _might_ be unsafe.
        let result : Result< #return_ty, ::intercom::ComError > = ( || unsafe {
            #( #out_arg_declarations )*;
            let #return_ident = ((**vtbl).#method_ident)( #( #params ),* );
            let INTERCOM_iid = #iid_tokens;
            Ok( { #return_statement } )
        } )();
        return match result {
            Ok( v ) => v,
            Err( err ) => < #return_ty as ::intercom::ErrorValue >::from_com_error( err ),
        };
    )
}
fn rust_to_com_delegate ( itf_variant : & model :: ComInterfaceVariant , method_info : & ComMethodInfo , vtable_ident : & Ident , ) -> TokenStream { // The COM out-arguments that mirror the Rust return value will // require temporary variables during the COM call. Format their // declarations. let out_arg_declarations = method_info . returnhandler . com_out_args ( ) . iter ( ) . map ( | ca | { let ident = & ca . name ; let ty = & ca . handler . com_ty ( Direction :: Retval ) ; let default = ca . handler . default_value ( ) ; quote ! ( let mut ident ty default ) } ) . collect :: < Vec < _ > > ( ) ; // Format the in and out parameters for the COM call. let ( temporaries , params ) : ( Vec < _ > , Vec < _ > ) = method_info . raw_com_args ( ) . into_iter ( ) . map ( | com_arg | { let name = com_arg . name ; match com_arg . dir { Direction :: In => { let param = com_arg . handler . rust_to_com ( & name , Direction :: In ) ; ( param . temporary , param . value ) } , Direction :: Out | Direction :: Retval => ( None , quote ! ( mut name ) ) , } } ) . unzip ( ) ; // Combine the parameters into the final parameter list. // This includes the 'this' pointer and both the IN and OUT // parameters. let params = iter :: once ( quote ! ( comptr ptr ) ) . chain ( params ) ; // Create the return statement. let return_ident = Ident :: new ( " " , Span :: call_site ( ) ) ; let return_statement = method_info . returnhandler . com_to_rust_return ( & return_ident ) ; // Resolve some of the fields needed for quote. let method_ident = & method_info . unique_name ; let return_ty = & method_info . rust_return_ty ; let iid_tokens = utils :: get_guid_tokens ( itf_variant . iid ( ) ) ; // Construct the final method. quote ! ( let vtbl comptr ptr as const const vtable_ident ( temporaries ) // Use an IIFE to act as a try/catch block. The various template // substitutions might end up using ?'s for error handling. The IIFE allows // us to handle the results here immediately. [ allow ( unused_unsafe ) ] // The fn itself _might_ be unsafe. let result Result return_ty intercom ComError ( unsafe { ( out_arg_declarations ) let return_ident ( ( vtbl ) method_ident ) ( ( params ) ) let INTERCOM_iid iid_tokens Ok ( { return_statement } ) } ) ( ) return match result { Ok ( v ) v Err ( err ) return_ty as intercom ErrorValue from_com_error ( err ) } ) }
Creates the functions responsible for delegating calls from Rust to COM
interfaces.
Creates the functions responsible for delegating calls from Rust to COM interfaces .
itf_variant
&model::ComInterfaceVariant
method_info
&ComMethodInfo
vtable_ident
&Ident