extendr_macros/
extendr_function.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::{extendr_options::ExtendrOptions, wrappers};
use proc_macro::TokenStream;
use quote::quote;
use syn::ItemFn;

/// Generate bindings for a single function.
pub(crate) fn extendr_function(mut func: ItemFn, opts: &ExtendrOptions) -> TokenStream {
    let mut wrappers: Vec<ItemFn> = Vec::new();

    let res =
        wrappers::make_function_wrappers(opts, &mut wrappers, "", &func.attrs, &mut func.sig, None);
    if let Err(e) = res {
        return e.into_compile_error().into();
    };

    TokenStream::from(quote! {
        #func

        # ( #wrappers )*
    })
}