pub struct CWrapperContextBuilder {Show 31 fields
fn_ident: Ident,
r_name: Option<String>,
c_ident: Ident,
r_wrapper_const: Option<Ident>,
inputs: Punctuated<FnArg, Comma>,
inferred_signature: Option<TokenStream>,
output: ReturnType,
pre_call: Vec<TokenStream>,
post_conversion: 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,
err_parts: ErrPartsMode,
match_arg_several_ok_params: Vec<String>,
layered_choice_params: Vec<(String, ChoiceLeaf)>,
no_na_params: Vec<(String, Option<String>)>,
param_markers: Vec<(String, Vec<ParamMarker>)>,
formals: Formals,
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. The required call_expr
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).
r_name: Option<String>R-facing name for raised messages. Defaults to fn_ident.
c_ident: IdentC wrapper function identifier (set at construction).
r_wrapper_const: Option<Ident>R wrapper constant identifier for doc cross-references, if the wrapper has one.
inputs: Punctuated<FnArg, Comma>Function parameters (excluding self). Defaults to empty.
inferred_signature: Option<TokenStream>§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.
post_conversion: Vec<TokenStream>Statements after argument conversion, on R’s main thread.
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.
err_parts: ErrPartsModeHow Err values become condition parts.
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).
layered_choice_params: Vec<(String, ChoiceLeaf)>Layered choice parameters — forwarded to
RustConversionBuilder::with_layered_choice.
no_na_params: Vec<(String, Option<String>)>no_na parameters, forwarded to RustConversionBuilder::with_no_na.
param_markers: Vec<(String, Vec<ParamMarker>)>Marked parameters, forwarded to
RustConversionBuilder::with_param_markers.
formals: FormalsThe parameters’ R formals, forwarded to
RustConversionBuilder::with_formals.
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_name(self, r_name: String) -> Self
pub fn r_name(self, r_name: String) -> Self
Sets the name R calls the item by, used in the messages the wrapper raises in place of the Rust identifier. Share the resolved name with the R wrapper generator, including renames and postfixes.
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) the
wrapper’s rustdoc links to.
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 inferred_signature(self, callable: TokenStream) -> Self
pub fn inferred_signature(self, callable: TokenStream) -> Self
Infer inherited parameter types from this concrete method item.
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 post_conversion(self, stmts: Vec<TokenStream>) -> Self
pub fn post_conversion(self, stmts: Vec<TokenStream>) -> Self
Statements that need converted arguments, without shortening their scope.
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 err_parts(self, mode: ErrPartsMode) -> Self
pub fn err_parts(self, mode: ErrPartsMode) -> Self
Choose how Err values become condition parts (default: the
RConditionData/Debug probe). See ErrPartsMode.
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 layered_choice(self, param_name: String, leaf: ChoiceLeaf) -> Self
pub fn layered_choice(self, param_name: String, leaf: ChoiceLeaf) -> Self
Record a choice parameter whose type wraps the choice in Missing /
Option layers (#1473, #1551).
Passed through to RustConversionBuilder::with_layered_choice, which
decodes the layers outermost first (an omitted argument is
Missing::Absent, NULL is None) and the choice itself from leaf.
Sourcepub fn no_na(self, param_name: String, message: Option<String>) -> Self
pub fn no_na(self, param_name: String, message: Option<String>) -> Self
Record a #[miniextendr(no_na)] parameter (its Rust name) and the
author’s no_na(message = "..."), if any.
Passed through to RustConversionBuilder::with_no_na, which checks the
converted value (TryFromSexp::__mx_has_na) right after its binding,
for what the type reads as NA beyond the R guard’s anyNA(). An
Either has no R guard, and its value checks the input instead
(TryFromSexp::__mx_input_has_na).
Sourcepub fn param_markers(
self,
param_name: String,
markers: Vec<ParamMarker>,
) -> Self
pub fn param_markers( self, param_name: String, markers: Vec<ParamMarker>, ) -> Self
Record a parameter (its Rust name) whose declared type carries the
parameter markers (Checked<T> / Unchecked<T>, #1566, outermost
first). The inputs hold the inner type; the converted value is wrapped
in the markers before the call.
Sourcepub fn formals(self, formals: Formals) -> Self
pub fn formals(self, formals: Formals) -> Self
Name each parameter by its R formal (#1842) in the conversion errors
(their message and e$param); without it, the Rust name without
leading underscores.
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 was not set.
Auto Trait Implementations§
impl !Send for CWrapperContextBuilder
impl !Sync for CWrapperContextBuilder
impl Freeze for CWrapperContextBuilder
impl RefUnwindSafe 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> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§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: 920 bytes