Skip to main content

CWrapperContextBuilder

Struct CWrapperContextBuilder 

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

Rust function/method identifier (set at construction).

§c_ident: Ident

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

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

§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: 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_wrapper_const(self, ident: Ident) -> Self

Sets the R wrapper constant identifier (e.g., R_WRAPPER_my_func). Requiredbuild panics if not set.

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 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 call_expr(self, expr: TokenStream) -> Self

Sets the Rust call expression (e.g., my_func(arg0) or self_ref.method(arg0)). Requiredbuild 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 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 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 or r_wrapper_const 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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: 520 bytes