pub struct CWrapperContextBuilder {Show 23 fields
fn_ident: Ident,
c_ident: Ident,
r_wrapper_const: Option<Ident>,
inputs: Punctuated<FnArg, Comma>,
output: ReturnType,
pre_call: Vec<TokenStream>,
call_expr: Option<TokenStream>,
thread_strategy: Option<ThreadStrategy>,
return_handling: Option<ReturnHandling>,
coerce_all: bool,
coerce_params: Vec<String>,
check_interrupt: bool,
rng: bool,
cfg_attrs: Vec<Attribute>,
type_context: Option<Ident>,
has_self: bool,
call_method_def_ident: Option<Ident>,
strict: bool,
match_arg_several_ok_params: Vec<String>,
preserve_param_names: bool,
vis: Visibility,
generics: Generics,
skip_wrapper: bool,
}Expand description
Builder for CWrapperContext.
Created via CWrapperContext::builder. All fields except fn_ident and c_ident
(provided at construction) default to empty/false/None. Required fields (call_expr,
r_wrapper_const) must be set before calling build or it will panic.
Optional fields like thread_strategy and return_handling are auto-detected from
the function signature if not explicitly set.
Fields§
§fn_ident: IdentRust function/method identifier (set at construction).
c_ident: IdentC wrapper function identifier (set at construction).
r_wrapper_const: Option<Ident>R wrapper constant identifier for doc cross-references. Required.
inputs: Punctuated<FnArg, Comma>Function parameters (excluding self). Defaults to empty.
output: ReturnTypeRust return type. Defaults to () (no return type annotation).
pre_call: Vec<TokenStream>Pre-call statements emitted before the call expression. Defaults to empty.
call_expr: Option<TokenStream>The Rust call expression. Required.
thread_strategy: Option<ThreadStrategy>Thread strategy override. If None, defaults to ThreadStrategy::MainThread.
return_handling: Option<ReturnHandling>Return handling override. If None, auto-detected from output via detect_return_handling.
coerce_all: boolEnable coercing conversion for all parameters.
coerce_params: Vec<String>Names of individual parameters with coercing conversion enabled.
check_interrupt: boolEmit R_CheckUserInterrupt() before the call.
rng: boolWrap call in GetRNGstate()/PutRNGstate().
cfg_attrs: Vec<Attribute>#[cfg(...)] attributes to propagate to generated items.
type_context: Option<Ident>Type identifier for method context (e.g., MyStruct). None for standalone functions.
has_self: boolWhether the original method has a self receiver.
call_method_def_ident: Option<Ident>Custom call_method_def constant name override.
strict: boolEnable strict checked conversions for lossy return types.
match_arg_several_ok_params: Vec<String>Parameter names with match_arg + several_ok — forwarded to
RustConversionBuilder::with_match_arg_several_ok so each element of the
Vec is decoded via match_arg_vec_from_sexp (enum’s MatchArg::CHOICES).
preserve_param_names: boolWhen true, use original parameter names in C wrapper signature (for rustdoc).
vis: VisibilityVisibility of the generated extern "C-unwind" wrapper.
generics: GenericsGeneric parameters for the C wrapper signature.
skip_wrapper: boolWhen true, skip wrapper body but still emit R_CallMethodDef.
Implementations§
Source§impl CWrapperContextBuilder
impl CWrapperContextBuilder
Sourcepub fn r_wrapper_const(self, ident: Ident) -> Self
pub fn r_wrapper_const(self, ident: Ident) -> Self
Sets the R wrapper constant identifier (e.g., R_WRAPPER_my_func).
Required – build panics if not set.
Sourcepub fn inputs(self, inputs: Punctuated<FnArg, Comma>) -> Self
pub fn inputs(self, inputs: Punctuated<FnArg, Comma>) -> Self
Sets the function parameters (excluding self receiver).
Each input becomes a SEXP argument in the C wrapper.
Sourcepub fn output(self, output: ReturnType) -> Self
pub fn output(self, output: ReturnType) -> Self
Sets the Rust return type. Used for auto-detecting ReturnHandling
and for strict-mode type inspection.
Sourcepub fn pre_call(self, stmts: Vec<TokenStream>) -> Self
pub fn pre_call(self, stmts: Vec<TokenStream>) -> Self
Sets pre-call statements emitted before the call expression. Typically used for self-extraction in instance methods.
Sourcepub fn call_expr(self, expr: TokenStream) -> Self
pub fn call_expr(self, expr: TokenStream) -> Self
Sets the Rust call expression (e.g., my_func(arg0) or self_ref.method(arg0)).
Required – build panics if not set.
Sourcepub fn thread_strategy(self, strategy: ThreadStrategy) -> Self
pub fn thread_strategy(self, strategy: ThreadStrategy) -> Self
Overrides the thread strategy. If not called, defaults to ThreadStrategy::MainThread.
Sourcepub fn return_handling(self, handling: ReturnHandling) -> Self
pub fn return_handling(self, handling: ReturnHandling) -> Self
Overrides the return handling strategy. If not called, auto-detected from output
via detect_return_handling.
Sourcepub fn coerce_all(self) -> Self
pub fn coerce_all(self) -> Self
Enables coercing conversion for all parameters via Rf_coerceVector.
Sourcepub fn with_coerce_param(self, param_name: String) -> Self
pub fn with_coerce_param(self, param_name: String) -> Self
Enables coercing conversion for a specific named parameter.
Sourcepub fn check_interrupt(self) -> Self
pub fn check_interrupt(self) -> Self
Enables R_CheckUserInterrupt() before the call expression.
Sourcepub fn cfg_attrs(self, attrs: Vec<Attribute>) -> Self
pub fn cfg_attrs(self, attrs: Vec<Attribute>) -> Self
Sets #[cfg(...)] attributes to propagate to the C wrapper and call_method_def.
Sourcepub fn type_context(self, type_ident: Ident) -> Self
pub fn type_context(self, type_ident: Ident) -> Self
Sets the type context for methods (e.g., MyStruct). Used in doc comments
and default call_method_def naming.
Sourcepub fn has_self(self) -> Self
pub fn has_self(self) -> Self
Marks this as an instance method with a self receiver.
Causes the C wrapper to include a self_sexp parameter.
Sourcepub fn strict(self) -> Self
pub fn strict(self) -> Self
Enables strict checked conversions for lossy return types (i64, u64, isize,
usize and their Vec variants).
Sourcepub fn match_arg_several_ok(self, param_name: String) -> Self
pub fn match_arg_several_ok(self, param_name: String) -> Self
Record a parameter as match_arg + several_ok.
Passed through to RustConversionBuilder::with_match_arg_several_ok, which
switches that parameter’s conversion from TryFromSexp to
match_arg_vec_from_sexp::<Inner> so each STRSXP element is validated against
the enum’s MatchArg::CHOICES.
Sourcepub fn call_method_def_ident(self, ident: Ident) -> Self
pub fn call_method_def_ident(self, ident: Ident) -> Self
Set a custom call_method_def identifier.
If not set, the default naming is used:
- With type_context:
call_method_def_{type}_{method} - Without:
call_method_def_{method}
Sourcepub fn preserve_param_names(self) -> Self
pub fn preserve_param_names(self) -> Self
Preserve original parameter names in the C wrapper signature.
When true, build_c_params uses the original identifier from inputs instead
of renaming to arg_N. Enables rustdoc to show descriptive parameter names.
Used by the standalone-fn path; impl methods use the default arg_N form.
Sourcepub fn vis(self, vis: Visibility) -> Self
pub fn vis(self, vis: Visibility) -> Self
Set the visibility of the generated extern "C-unwind" wrapper.
Defaults to syn::Visibility::Inherited. Standalone fns forward the user’s
declared visibility (pub, pub(crate), etc.).
Sourcepub fn generics(self, generics: Generics) -> Self
pub fn generics(self, generics: Generics) -> Self
Set the generic parameters for the C wrapper function signature.
Defaults to empty generics. Standalone fns with generic parameters must forward them so the generated wrapper is also generic.
Sourcepub fn skip_wrapper(self) -> Self
pub fn skip_wrapper(self) -> Self
Skip generating the wrapper body and only emit the R_CallMethodDef.
Use this when the Rust fn is already extern "C-unwind" with #[no_mangle] or
#[unsafe(no_mangle)] (the user wrote the C symbol directly). The function still
needs to be registered with R via R_CallMethodDef.
When set, numArgs is computed from inputs directly (no synthetic
__miniextendr_call param).
Sourcepub fn build(self) -> CWrapperContext
pub fn build(self) -> CWrapperContext
Consumes the builder and returns a fully configured CWrapperContext.
If thread_strategy was not set, defaults to ThreadStrategy::MainThread.
If return_handling was not set, auto-detects from the output type via
detect_return_handling.
§Panics
Panics if call_expr or r_wrapper_const was not set.
Auto Trait Implementations§
impl Freeze for CWrapperContextBuilder
impl RefUnwindSafe for CWrapperContextBuilder
impl !Send for CWrapperContextBuilder
impl !Sync for CWrapperContextBuilder
impl Unpin for CWrapperContextBuilder
impl UnsafeUnpin for CWrapperContextBuilder
impl UnwindSafe for CWrapperContextBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 520 bytes