Skip to main content

CWrapperContextBuilder

Struct CWrapperContextBuilder 

Source
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: Ident

Rust function/method identifier (set at construction).

§r_name: Option<String>

R-facing name for raised messages. Defaults to fn_ident.

§c_ident: Ident

C 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: ReturnType

Rust 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: bool

Enable coercing conversion for all parameters.

§coerce_params: Vec<String>

Names of individual parameters with coercing conversion enabled.

§check_interrupt: bool

Emit R_CheckUserInterrupt() before the call.

§rng: bool

Wrap 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: bool

Whether the original method has a self receiver.

§call_method_def_ident: Option<Ident>

Custom call_method_def constant name override.

§strict: bool

Enable strict checked conversions for lossy return types.

§err_parts: ErrPartsMode

How 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: Formals

The parameters’ R formals, forwarded to RustConversionBuilder::with_formals.

§preserve_param_names: bool

When true, use original parameter names in C wrapper signature (for rustdoc).

§vis: Visibility

Visibility of the generated extern "C-unwind" wrapper.

§generics: Generics

Generic parameters for the C wrapper signature.

§skip_wrapper: bool

When true, skip wrapper body but still emit R_CallMethodDef.

Implementations§

Source§

impl CWrapperContextBuilder

Source

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.

Source

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.

Source

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.

Source

pub fn inferred_signature(self, callable: TokenStream) -> Self

Infer inherited parameter types from this concrete method item.

Source

pub fn output(self, output: ReturnType) -> Self

Sets the Rust return type. Used for auto-detecting ReturnHandling and for strict-mode type inspection.

Source

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.

Source

pub fn post_conversion(self, stmts: Vec<TokenStream>) -> Self

Statements that need converted arguments, without shortening their scope.

Source

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.

Source

pub fn thread_strategy(self, strategy: ThreadStrategy) -> Self

Overrides the thread strategy. If not called, defaults to ThreadStrategy::MainThread.

Source

pub fn return_handling(self, handling: ReturnHandling) -> Self

Overrides the return handling strategy. If not called, auto-detected from output via detect_return_handling.

Source

pub fn coerce_all(self) -> Self

Enables coercing conversion for all parameters via Rf_coerceVector.

Source

pub fn with_coerce_param(self, param_name: String) -> Self

Enables coercing conversion for a specific named parameter.

Source

pub fn check_interrupt(self) -> Self

Enables R_CheckUserInterrupt() before the call expression.

Source

pub fn rng(self) -> Self

Enable RNG state management (GetRNGstate/PutRNGstate).

Source

pub fn cfg_attrs(self, attrs: Vec<Attribute>) -> Self

Sets #[cfg(...)] attributes to propagate to the C wrapper and call_method_def.

Source

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.

Source

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.

Source

pub fn strict(self) -> Self

Enables strict checked conversions for lossy return types (i64, u64, isize, usize and their Vec variants).

Source

pub fn err_parts(self, mode: ErrPartsMode) -> Self

Choose how Err values become condition parts (default: the RConditionData/Debug probe). See ErrPartsMode.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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}
Source

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.

Source

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.).

Source

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.

Source

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).

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

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