pub fn new(
        decl: &Signature,
        type_system: ModelTypeSystem,
    ) -> Result<ComMethodInfo, ComMethodInfoError>
    {
        // Process all the function arguments.
        // In Rust this includes the 'self' argument and the actual function
        // arguments. For COM the self is implicit so we'll handle it
        // separately.
        let n = decl.ident.clone();
        let unsafety = decl.unsafety.is_some();
        let mut iter = decl.inputs.iter();
        let rust_self_arg = iter.next().ok_or(ComMethodInfoError::TooFewArguments)?;

        let (is_const, rust_self_arg) = match *rust_self_arg {
            FnArg::Receiver(ref self_arg) => (self_arg.mutability.is_none(), self_arg.clone()),
            _ => return Err(ComMethodInfoError::BadSelfArg),
        };

        // Process other arguments.
        let args = iter
            .map(|arg| {
                let ty = arg
                    .get_ty()
                    .map_err(|_| ComMethodInfoError::BadArg(Box::new(arg.clone())))?;
                let ident = arg
                    .get_ident()
                    .map_err(|_| ComMethodInfoError::BadArg(Box::new(arg.clone())))?;

                Ok(RustArg::new(ident, ty, arg.span(), type_system))
            })
            .collect::<Result<_, _>>()?;

        // Get the output.
        let rust_return_ty = match decl.output {
            ReturnType::Default => syn::parse2(quote_spanned!(decl.span() => ())).unwrap(),
            ReturnType::Type(_, ref ty) => (**ty).clone(),
        };

        // Resolve the return type and retval type.
        let (retval_type, return_type, retval_span) = if utils::is_unit(&rust_return_ty) {
            (None, None, decl.span())
        } else if let Some((retval, ret)) = try_parse_result(&rust_return_ty) {
            (Some(retval), Some(ret), decl.output.span())
        } else {
            (None, Some(rust_return_ty.clone()), decl.output.span())
        };

        let returnhandler =
            get_return_handler(&retval_type, &return_type, retval_span, type_system)
                .or(Err(ComMethodInfoError::BadReturnType))?;
        Ok(ComMethodInfo {
            name: n,
            infallible: returnhandler.is_infallible(),
            returnhandler: returnhandler.into(),
            signature_span: decl.span(),
            is_const,
            rust_self_arg,
            rust_return_ty,
            retval_type,
            return_type,
            args,
            is_unsafe: unsafety,
            type_system,
        })
    }
/// Constructs new COM method info from a Rust method signature.
Constructs new COM method info from a Rust method signature.
Constructs new COM method info from a Rust method signature .
pub fn new(
        decl: &Signature,
        type_system: ModelTypeSystem,
    ) -> Result<ComMethodInfo, ComMethodInfoError>
    {
        // Process all the function arguments.
        // In Rust this includes the 'self' argument and the actual function
        // arguments. For COM the self is implicit so we'll handle it
        // separately.
        let n = decl.ident.clone();
        let unsafety = decl.unsafety.is_some();
        let mut iter = decl.inputs.iter();
        let rust_self_arg = iter.next().ok_or(ComMethodInfoError::TooFewArguments)?;
        let (is_const, rust_self_arg) = match *rust_self_arg {
            FnArg::Receiver(ref self_arg) => (self_arg.mutability.is_none(), self_arg.clone()),
            _ => return Err(ComMethodInfoError::BadSelfArg),
        };
        // Process other arguments.
        let args = iter
            .map(|arg| {
                let ty = arg
                    .get_ty()
                    .map_err(|_| ComMethodInfoError::BadArg(Box::new(arg.clone())))?;
                let ident = arg
                    .get_ident()
                    .map_err(|_| ComMethodInfoError::BadArg(Box::new(arg.clone())))?;
                Ok(RustArg::new(ident, ty, arg.span(), type_system))
            })
            .collect::<Result<_, _>>()?;
        // Get the output.
        let rust_return_ty = match decl.output {
            ReturnType::Default => syn::parse2(quote_spanned!(decl.span() => ())).unwrap(),
            ReturnType::Type(_, ref ty) => (**ty).clone(),
        };
        // Resolve the return type and retval type.
        let (retval_type, return_type, retval_span) = if utils::is_unit(&rust_return_ty) {
            (None, None, decl.span())
        } else if let Some((retval, ret)) = try_parse_result(&rust_return_ty) {
            (Some(retval), Some(ret), decl.output.span())
        } else {
            (None, Some(rust_return_ty.clone()), decl.output.span())
        };
        let returnhandler =
            get_return_handler(&retval_type, &return_type, retval_span, type_system)
                .or(Err(ComMethodInfoError::BadReturnType))?;
        Ok(ComMethodInfo {
            name: n,
            infallible: returnhandler.is_infallible(),
            returnhandler: returnhandler.into(),
            signature_span: decl.span(),
            is_const,
            rust_self_arg,
            rust_return_ty,
            retval_type,
            return_type,
            args,
            is_unsafe: unsafety,
            type_system,
        })
    }
pub fn new ( decl : & Signature , type_system : ModelTypeSystem , ) -> Result < ComMethodInfo , ComMethodInfoError > { // Process all the function arguments. // In Rust this includes the 'self' argument and the actual function // arguments. For COM the self is implicit so we'll handle it // separately. let n = decl . ident . clone ( ) ; let unsafety = decl . unsafety . is_some ( ) ; let mut iter = decl . inputs . iter ( ) ; let rust_self_arg = iter . next ( ) . ok_or ( ComMethodInfoError :: TooFewArguments ) ? ; let ( is_const , rust_self_arg ) = match * rust_self_arg { FnArg :: Receiver ( ref self_arg ) => ( self_arg . mutability . is_none ( ) , self_arg . clone ( ) ) , _ => return Err ( ComMethodInfoError :: BadSelfArg ) , } ; // Process other arguments. let args = iter . map ( | arg | { let ty = arg . get_ty ( ) . map_err ( | _ | ComMethodInfoError :: BadArg ( Box :: new ( arg . clone ( ) ) ) ) ? ; let ident = arg . get_ident ( ) . map_err ( | _ | ComMethodInfoError :: BadArg ( Box :: new ( arg . clone ( ) ) ) ) ? ; Ok ( RustArg :: new ( ident , ty , arg . span ( ) , type_system ) ) } ) . collect :: < Result < _ , _ > > ( ) ? ; // Get the output. let rust_return_ty = match decl . output { ReturnType :: Default => syn :: parse2 ( quote_spanned ! ( decl span ( ) ( ) ) ) . unwrap ( ) , ReturnType :: Type ( _ , ref ty ) => ( * * ty ) . clone ( ) , } ; // Resolve the return type and retval type. let ( retval_type , return_type , retval_span ) = if utils :: is_unit ( & rust_return_ty ) { ( None , None , decl . span ( ) ) } else if let Some ( ( retval , ret ) ) = try_parse_result ( & rust_return_ty ) { ( Some ( retval ) , Some ( ret ) , decl . output . span ( ) ) } else { ( None , Some ( rust_return_ty . clone ( ) ) , decl . output . span ( ) ) } ; let returnhandler = get_return_handler ( & retval_type , & return_type , retval_span , type_system ) . or ( Err ( ComMethodInfoError :: BadReturnType ) ) ? ; Ok ( ComMethodInfo { name : n , infallible : returnhandler . is_infallible ( ) , returnhandler : returnhandler . into ( ) , signature_span : decl . span ( ) , is_const , rust_self_arg , rust_return_ty , retval_type , return_type , args , is_unsafe : unsafety , type_system , } ) }
Constructs new COM method info from a Rust method signature.
Constructs new COM method info from a Rust method signature .
decl
&Signature
type_system
ModelTypeSystem
decl
&Signature
type_system
ModelTypeSystem