pub fn emit_v2_operation(input: TokenStream) -> TokenStream {
    let mut item_ast: ItemFn = match syn::parse(input) {
        Ok(s) => s,
        Err(e) => {
            emit_error!(e.span().unwrap(), "operation must be a function.");
            return quote!().into();
        }
    };

    let mut wrapper = None;
    match &mut item_ast.sig.output {
        ReturnType::Default => {
            emit_warning!(
                item_ast.span().unwrap(),
                "operation doesn't seem to return a response."
            );
        }
        ReturnType::Type(_, ty) => {
            let t = quote!(#ty).to_string();
            // FIXME: This is a hack for functions returning known
            // `impl Trait`. Need a better way!
            if t.contains("Responder") {
                wrapper = Some(quote!(paperclip::actix::ResponderWrapper));
            }

            if let (Type::ImplTrait(_), Some(ref w)) = (&**ty, wrapper.as_ref()) {
                if item_ast.sig.asyncness.is_some() {
                    *ty = Box::new(syn::parse2(quote!(#w<#ty>)).expect("parsing wrapper type"));
                } else {
                    *ty = Box::new(
                        syn::parse2(quote!(impl Future<Output=#w<#ty>>))
                            .expect("parsing wrapper type"),
                    );
                }
            }
        }
    }

    if let Some(w) = wrapper {
        let block = item_ast.block;
        let wrapped_value = if item_ast.sig.asyncness.is_some() {
            quote!(#w(f))
        } else {
            quote!(futures::future::ready(#w(f)))
        };
        item_ast.block = Box::new(
            syn::parse2(quote!(
                {
                    let f = (|| {
                        #block
                    })();
                    #wrapped_value
                }
            ))
            .expect("parsing wrapped block"),
        );
    }

    quote!(
        #item_ast
    )
    .into()
}
/// Actual parser and emitter for `api_v2_operation` macro.
///
/// **NOTE:** This is a no-op right now. It's only reserved for
/// future use to avoid introducing breaking changes.
Actual parser and emitter for `api_v2_operation` macro.
NOTE:** This is a no-op right now. It's only reserved for
future use to avoid introducing breaking changes.
Actual parser and emitter for ` api_v2_operation ` macro . NOTE : ** This is a no - op right now . It ' s only reserved for future use to avoid introducing breaking changes .
pub fn emit_v2_operation(input: TokenStream) -> TokenStream {
    let mut item_ast: ItemFn = match syn::parse(input) {
        Ok(s) => s,
        Err(e) => {
            emit_error!(e.span().unwrap(), "operation must be a function.");
            return quote!().into();
        }
    };
    let mut wrapper = None;
    match &mut item_ast.sig.output {
        ReturnType::Default => {
            emit_warning!(
                item_ast.span().unwrap(),
                "operation doesn't seem to return a response."
            );
        }
        ReturnType::Type(_, ty) => {
            let t = quote!(#ty).to_string();
            // FIXME: This is a hack for functions returning known
            // `impl Trait`. Need a better way!
            if t.contains("Responder") {
                wrapper = Some(quote!(paperclip::actix::ResponderWrapper));
            }
            if let (Type::ImplTrait(_), Some(ref w)) = (&**ty, wrapper.as_ref()) {
                if item_ast.sig.asyncness.is_some() {
                    *ty = Box::new(syn::parse2(quote!(#w<#ty>)).expect("parsing wrapper type"));
                } else {
                    *ty = Box::new(
                        syn::parse2(quote!(impl Future<Output=#w<#ty>>))
                            .expect("parsing wrapper type"),
                    );
                }
            }
        }
    }
    if let Some(w) = wrapper {
        let block = item_ast.block;
        let wrapped_value = if item_ast.sig.asyncness.is_some() {
            quote!(#w(f))
        } else {
            quote!(futures::future::ready(#w(f)))
        };
        item_ast.block = Box::new(
            syn::parse2(quote!(
                {
                    let f = (|| {
                        #block
                    })();
                    #wrapped_value
                }
            ))
            .expect("parsing wrapped block"),
        );
    }
    quote!(
        #item_ast
    )
    .into()
}
pub fn emit_v2_operation ( input : TokenStream ) -> TokenStream { let mut item_ast : ItemFn = match syn :: parse ( input ) { Ok ( s ) => s , Err ( e ) => { emit_error ! ( e span ( ) unwrap ( ) " " ) ; return quote ! ( ) . into ( ) ; } } ; let mut wrapper = None ; match & mut item_ast . sig . output { ReturnType :: Default => { emit_warning ! ( item_ast span ( ) unwrap ( ) " " ) ; } ReturnType :: Type ( _ , ty ) => { let t = quote ! ( ty ) . to_string ( ) ; // FIXME: This is a hack for functions returning known // `impl Trait`. Need a better way! if t . contains ( " " ) { wrapper = Some ( quote ! ( paperclip actix ResponderWrapper ) ) ; } if let ( Type :: ImplTrait ( _ ) , Some ( ref w ) ) = ( & * * ty , wrapper . as_ref ( ) ) { if item_ast . sig . asyncness . is_some ( ) { * ty = Box :: new ( syn :: parse2 ( quote ! ( w ty ) ) . expect ( " " ) ) ; } else { * ty = Box :: new ( syn :: parse2 ( quote ! ( impl Future Output w ty ) ) . expect ( " " ) , ) ; } } } } if let Some ( w ) = wrapper { let block = item_ast . block ; let wrapped_value = if item_ast . sig . asyncness . is_some ( ) { quote ! ( w ( f ) ) } else { quote ! ( futures future ready ( w ( f ) ) ) } ; item_ast . block = Box :: new ( syn :: parse2 ( quote ! ( { let f ( { block } ) ( ) wrapped_value } ) ) . expect ( " " ) , ) ; } quote ! ( item_ast ) . into ( ) }
Actual parser and emitter for `api_v2_operation` macro.
Actual parser and emitter for ` api_v2_operation ` macro .
input
TokenStream