Skip to main content

Module wrappers

Module wrappers 

Source
Expand description

This is responsible for generating the C functions that act as wrappers of the exported Rust functions.

extendr relies on the .Call-interface In short, it is necessary the the signature of the C-function have SEXP as the type for return type, and argument types.

For instance, if your function returns nothing, the return type is not allowed to be void, instead SEXP must be used, and one should return R_NilValue.

Β§R wrappers

Within R, you may call rextendr::document() to generate R functions, that use the .Call-interface, to call the wrapped Rust functions.

You may also manually implement these wrappers, in order to do special type-checking, or other annotation, that could be more convenient to do on the R-side. The C-functions are named according to "{WRAP_PREFIX}{prefix}{mod_name}". See WRAP_PREFIX, and note that prefix is set specifically for methods in extendr-impl blocks, while for functions have no prefix.

Re-exportsΒ§

use proc_macro2::Ident; πŸ”’
use quote::format_ident; πŸ”’
use quote::quote; πŸ”’
use std::collections::HashMap; πŸ”’
use std::sync::Mutex; πŸ”’
use syn::parse_quote; πŸ”’
use syn::punctuated::Punctuated; πŸ”’
use syn::Expr; πŸ”’
use syn::ExprLit; πŸ”’
use syn::FnArg; πŸ”’
use syn::ItemFn; πŸ”’
use syn::Token; πŸ”’
use syn::Type; πŸ”’
use crate::extendr_options::ExtendrOptions; πŸ”’

StructsΒ§

STRUCT_DOCS πŸ”’

ConstantsΒ§

META_PREFIX
WRAP_PREFIX

FunctionsΒ§

get_defaults πŸ”’
get_doc_string
get_named_lit πŸ”’
get_return_type
get_struct_doc
Retrieve the struct‐level docs (or empty if none).
make_function_wrappers πŸ”’
mangled_type_name
register_struct_doc
Called by the struct‐level extendr-macro to register docstrings.
sanitize_identifier πŸ”’
translate_actual πŸ”’
translate_formal
translate_meta_arg πŸ”’
translate_only_alias πŸ”’
Returns only the alias from a function argument.
translate_to_robj πŸ”’
Convert SEXP arguments into Robj. This maintains the lifetime of references.
type_name
Return a simplified type name that will be meaningful to R. Defaults to a digest.
type_needs_mut_robj πŸ”’