Skip to main content

Module miniextendr_fn

Module miniextendr_fn 

Source
Expand description

Function signature parsing for #[miniextendr].

This module handles parsing and normalizing Rust function signatures for the #[miniextendr] attribute macro. It provides:

Structs§

MiniextendrFnAttrs 🔒
Parsed arguments for the #[miniextendr(...)] attribute on functions.
MiniextendrFunctionParsed 🔒
Parsed + normalized Rust function item for #[miniextendr].
ParamAttrs 🔒
Collapsed per-parameter attribute state for a single function parameter.
PerParamMiniextendrAttr 🔒
Parsed per-parameter #[miniextendr(...)] attribute content.
ROnExit 🔒
Parsed r_on_exit attribute for on.exit() cleanup code in R wrappers.
RenamePair 🔒
One from = "to" entry of rename(...). from is an identifier or, for a serde-renamed field whose name is not one, a string literal.
SerdeErrorSpec 🔒
#[miniextendr(serde_error)]: derive the Err arm’s condition class and data from the error type’s serde::Serialize output instead of the RConditionData/Debug probe.

Enums§

ClassCheck 🔒
The two class checks a parameter can name: inherits (the argument must inherit from one of the classes) and not_inherits (from none of them, #1815). Both take the same spellings at parameter and method level; this says which one a spelling is, and words its errors.
CoercionMapping 🔒
Conversion selected by coerce, shared by Rust conversion and R checks.
DotsKind 🔒
Which ... parameter type a parameter takes.
FieldType 🔒
The R type an as_* option gives a payload field.
ReturnPref 🔒
Preferred return-conversion path for IntoR.

Constants§

FN_BOOL_FLAGS_HELP 🔒
Comma-separated list of all fn-level boolean flags, for error messages.
FN_NESTED_OPTIONS_HELP 🔒
Comma-separated list of fn-level nested options, for error messages.
FORMAL_NOT_STRING 🔒
The error of a formal whose value is no string literal (#1842).
FORMAL_TWICE 🔒
The error of a second formal on one parameter (#1842).
MISSING_DEFAULT_PARAM_DOC 🔒
The generated @param text of an undocumented Missing<..> parameter with a formal default (#2161): the default only shows in the usage line, and an omitted argument still reaches Rust as Missing::Absent.
RESERVED_CONDITION_FIELDS 🔒
The condition’s own slots, mirrored from miniextendr_api::condition::RESERVED_CONDITION_FIELDS (the macros crate cannot depend on the API crate). The runtime check remains the backstop.
SERDE_ERROR_BARE_HELP 🔒
The bare flag / boolean forms: the serde path is not something to switch on per function.
SERDE_ERROR_OPTIONS_HELP 🔒
SERDE_ERROR_SHAPE_HELP 🔒
TRAIT_FORMAL_UNSUPPORTED 🔒
The error of a formal(...) on a trait method (#1842), declared or implemented. A trait method’s R formals are its declaration’s parameter names, shared by every implementing type and the trait ABI’s metadata; declared formals cover standalone functions and inherent impl methods.
WHEN_ON_NOT_INHERITS 🔒
The error for when(...) in not_inherits(...).

Functions§

absent_formals_by_r_name 🔒
The parameters of per_param (keyed by Rust name) whose wrapper reads a value identical() to the formal as omitted (ParamAttrs::absent_formal, #2152), as R formal → the formal’s default: the match_arg placeholder keyed by the C wrapper c_ident, or the literal choices(...) vector. For crate::r_wrapper_builder::RArgumentBuilder::with_absent_formals.
both 🔒
A field named by two options that exclude each other.
check_lazy_dots_params 🔒
Check the LazyDots parameters of a signature (#1892): LazyDots is the parameter’s whole type, taken by value (&LazyDots, Option<LazyDots>, Vec<LazyDots> are refused; Missing<LazyDots> is refused by validate_param_type), and no per-parameter option names it (has_options, keyed by Rust name): the wrapper passes its frame, and every option would force the dots or has nothing to act on.
check_nargs_params 🔒
Check the NArgs parameters of a signature (#1860): at most one, and none that a per-parameter option names (has_options, keyed by Rust name). The parameter is no R argument (the wrapper fills it with nargs()), so an option would have nothing to act on.
check_param_preconditions 🔒
Reject a parameter’s rank-1 precondition decision where it has nothing to act on: a match_arg / choices parameter (validated by match.arg(), never by type checks) and a type without type-derived checks (SEXP, Missing<T>, ExternalPtr<T>, &Dots, a type the check table does not know). ty is the parameter’s type with the markers peeled, which the errors point at; markers are the ones it carried. A no-op when the parameter decides nothing itself.
check_replacement_value_param 🔒
Check that an S3 method for a replacement generic takes the new value last, as value.
check_rng_guard_params 🔒
Check the RNG guard parameters of a signature (#2002): &RngGuard is filled by a #[miniextendr(rng)] wrapper (rng) with the guard it holds, so it needs rng, takes no per-parameter option (has_options, keyed by Rust name: it is no R argument) and appears at most once. Any other shape that names RngGuard (&mut RngGuard, by value, inside another type) is refused: the wrapper lends its guard for the call.
check_rng_seed 🔒
Check rng(seed = <param>) (#2198) against a standalone function’s signature and return the seed’s R formal. Every problem is reported at once:
choice_alternatives_suffix 🔒
The other values a choice parameter accepts, after its quoted choices: , or a data frame for an Either<.., R> layer (noun, the R arm), , or <null_word> for an Option<..> layer (optional), , a data frame, or <null_word> for both, nothing for neither. Shared by the parameter’s @param line (ParamAttrs::choice_doc_suffix, which passes NULL for no choice) and the argument error of an Either choice parameter (which passes NULL), so the two word the alternatives alike.
classify_choice_param 🔒
Record the layers of a match_arg / choices parameter’s type on its ParamAttrs (optional, omittable, either_noun) and reject the shapes the codegen cannot serve, now that the type is known. Shared by the standalone-fn parser and finalize_method_param_attrs so the two cannot classify a type differently. A no-op for other parameters.
collect_param_markers 🔒
The markers of every parameter of inputs that carries one, keyed by Rust name, in signature order. Nested or stacked markers are an error (see crate::type_inspect::peel_param_markers).
default_serde_error_prefix 🔒
Default family class for serde_error: <crate>_error, from the crate being compiled (cargo sets CARGO_CRATE_NAME for the rustc invocation that runs this proc macro).
dots_formal_error 🔒
The error of a formal on the dots parameter (#1842), at the literal.
dots_index 🔒
Position of the first ... parameter (&Dots or LazyDots) in inputs (receiver included, as RArgumentBuilder counts them), without validation: for code that runs after find_dots_param has accepted the signature.
dots_kind 🔒
The ... parameter type ty is, if any: Dots / &Dots (DotsKind::Forced), or LazyDots taken by value (DotsKind::Lazy, crate::type_inspect::is_lazy_dots_marker). &LazyDots and other shapes are none; the callers refuse them by name.
explicit_checks_by_r_name 🔒
The non-empty ParamAttrs::checks of per_param (keyed by Rust name), re-keyed by R formal (crate::r_wrapper_builder::Formals::of) for crate::r_preconditions::PreconditionOptions::explicit.
field_names 🔒
The non-empty string literals of skip(..) / as_*(..); problems go to errors.
finalize_method_param_attrs 🔒
Check an impl or trait method’s per-parameter attributes against its signature, now that it is known. Every parameter a method-level match_arg(...) / choices(...) / no_default(...) / inherits(...) / not_inherits(...) / no_na(...) / preconditions(...) / no_preconditions(...) / formal(...) names must exist (a typo would otherwise drop the option without a word); then a formal is refused on the &Dots parameter, whose formal is ..., a no_default(p) on a parameter that is no choice or has a default (no_default_conflict), the choice parameters are classified (see classify_choice_param), a class in both inherits and not_inherits is refused (crate::r_preconditions::ExplicitChecks::class_conflict), and each parameter’s own precondition decision is checked (check_param_preconditions). The standalone-fn path does the same while parsing; this is the twin for method-level attributes, whose parameter names arrive before the types. The inherent-impl and trait-impl parsers both call it, so they reject an unknown name the same way. inputs has the parameter markers peeled; markers are the ones peeled (empty on a trait impl, whose signature is the trait’s). span is where the errors point: the first such attribute, else the method name.
find_dots_param 🔒
Find the dots parameter of a signature by type, at any position, and return its Rust binding.
get_missing_inner_type 🔒
Extract the inner type T from Missing<T>, if the type is Missing<T>.
hint_class 🔒
One class name of a parameter-level when(...) hint: not empty.
inherits_hint 🔒
A parsed when(...) hint, which needs both its classes and its message.
init_marker_ident 🔒
The marker type miniextendr_init! defines at the crate root. A serde_error_shape! declaration is an impl keyed by it, which is what lets a crate declare a shape for an error type from another crate (#2207).
init_marker_path 🔒
crate::__MiniextendrInitMarker, as the generated Err arms pass it to the API’s probe macros. Those resolve it only under the API’s serde feature, where a shape can be declared.
is_dots_type 🔒
Check if a type is a ... parameter type: Dots / &Dots or LazyDots (see dots_kind).
is_missing_type 🔒
Check if a type is Missing<T>.
is_vector_like_type 🔒
Check if a type is a vector-like type that several_ok can populate.
merge_param_policy 🔒
Combine a parameter’s Checked<T> / Unchecked<T> marker with its keyword decision (keyword: the per-parameter preconditions / no_preconditions, or the method’s preconditions(p) / no_preconditions(p)). A marker is a type, not one more flag of the pair, so a marker and a keyword that disagree are an error, as a Call marker and call = ... are; agreeing ones are one decision. The error points at ty, the parameter’s type as written.
method_check_param 🔒
The parameter an entry of a method-level match_arg(...) / choices(...) / no_na(...) / inherits(...) / not_inherits(...) names, spelled as the signature’s crate::naming::ident_name (r#type names type), so finalize_method_param_attrs finds it.
method_class_list 🔒
The classes of a method-level inherits / not_inherits entry: a comma-separated, non-empty list.
missing_choice_default_msg 🔒
A default on a choice parameter under Missing<..> (#2161). An omitted argument reaches Rust as Missing::Absent, so the default would pick no choice; on a choices(...) list it would also replace the formal, the choice vector that ParamAttrs::absent_formal compares a supplied value with (#2152).
missing_default_param_docs 🔒
R formal → MISSING_DEFAULT_PARAM_DOC for each Missing<..> parameter of inputs that has a formal default in defaults (keyed by Rust name, as the per-parameter options are) and is no choice parameter of per_param, whose own line names the choices. The key is the formal formals gives the parameter, a declared formal included (#1842). Missing<Quoted> / Missing<Quosure> count too: their default is never evaluated either.
no_default_conflict 🔒
The error of a no_default that cannot apply (#1828), or None: on a parameter that is neither match_arg nor choices (only a choice parameter gets a generated default to drop), or together with a default. method_list picks the spellings named: the method-level no_default(p) / defaults(p = ...), else the parameter’s own no_default / default = "...".
non_empty_lit_str 🔒
A tag = "..." / prefix = "..." value: a non-empty string literal.
optional_choice_default_msg 🔒
parse_class_check_list 🔒
inherits(...) / not_inherits(...) on a parameter (check says which): each string literal, and each class = "...", names one class (the argument must inherit from one of them, or from none of them); message = "..." gives the condition message of a failure, for all of them. No string is split on commas, as with inherits = "cls" (the method-level class = "a, b" is split, see parse_method_class_check).
parse_lit_str 🔒
parse_method_class_check 🔒
Method-level inherits(p = "a, b", q(class = "a, b", message = "...")) / not_inherits(...) (the same shape, check says which) on an impl or trait method: each entry names a parameter and the classes it must inherit from (one of) or must not inherit from (any of), optionally with the condition message of the class check. A nested value cannot be a bare list of literals, so the classes are one comma-separated string, as in choices(p = "a, b"). inherits(q(class = "a", when(class = "b, c", message = "..."))) adds a hint (#1824; parse_method_when). Shared by the inherent-impl and trait-impl method parsers.
parse_method_formal 🔒
Parse a method-level formal(conf_int = "conf.int", ...) (#1842): the R formal of each named parameter, the method form of a standalone function’s per-parameter formal = "..". Shared by the inherent-impl parser only: trait methods take their formals from the trait declaration, and the trait parsers refuse it. A parameter named twice is an error; finalize_method_param_attrs refuses a name that is no parameter, and crate::r_wrapper_builder::check_r_formals checks each formal.
parse_method_no_default 🔒
Method-level no_default(p, q) on an impl or trait method, whose parameters cannot carry attributes: each entry names a match_arg / choices parameter whose R formal has no default (#1828). Shared by the inherent-impl and trait-impl method parsers; finalize_method_param_attrs refuses a name that is no parameter, no choice or has a default.
parse_method_no_na 🔒
Method-level no_na(p, q(message = "...")) on an impl or trait method, whose parameters cannot carry attributes: each entry names a parameter, optionally with the condition message of its NA check. Shared by the inherent-impl and trait-impl method parsers.
parse_method_preconditions 🔒
Method-level preconditions(p, q) / no_preconditions(p) on an impl or trait method, whose parameters cannot carry attributes: each entry names a parameter that keeps (keep) or drops its type-derived R-side checks. Naming one parameter twice follows the pair rule: the last one written wins. Shared by the inherent-impl and trait-impl method parsers; the bare preconditions / no_preconditions (the whole method) is theirs to read.
parse_method_when 🔒
A method-level when(class = "a, b", message = "...") hint in inherits(p(...)): its classes are one comma-separated string, as the entry’s own class, and its message is required.
parse_no_na_list 🔒
no_na(message = "...") on a parameter: no_na with the condition message of a failure.
parse_no_na_option 🔒
One option inside no_na(...) (parameter level) or no_na(p(...)) (method level): only message = "...".
parse_per_param_attr 🔒
Parse all per-parameter options from a #[miniextendr(...)] attribute.
parse_rng_seed 🔒
Parse rng(seed = <param>) (#2198): the parameter, by its Rust name, whose value the wrapper passes to set.seed().
parse_serde_error_list 🔒
Parse serde_error(shape = .., tag = "...", prefix = "...", skip(...), rename(...), as_*(...)) given as a Meta::List.
parse_serde_error_nested 🔒
Parse the tail of a serde_error option inside parse_nested_meta. Only the option list (shape = .., tag = "...", skip(...), as_character(...), ...) is accepted; the bare flag and = true/false are rejected with SERDE_ERROR_BARE_HELP, since the serde path is on for every eligible error type under the serde feature.
parse_when_list 🔒
The content of a parameter-level when(...) hint in inherits(...) (key is the when keyword, for error spans): its classes, spelled as in inherits(...) (each string literal and each class = "..." names one class, none split on commas), and its required message = "...".
peeled_inputs 🔒
inputs with each marked parameter’s type replaced by the type under its markers (markers, keyed by Rust name): what every R-side consumer and the conversion see. The item re-emitted for the user keeps the markers.
per_param_in_signature_order 🔒
The entries of per_param in the order their parameters appear in inputs. Code that emits one line or item per parameter walks this, never the map itself: a HashMap’s order differs between maps and between compiler runs, so the generated R wrapper (and the Rust items) would too.
preconditions_keyword 🔒
The keyword spelling of a rank-1 precondition decision, for messages: the per-parameter attribute on a function parameter, the method-level list on a method.
refuse_lazy_dots_in_trait_method 🔒
Refuse a LazyDots parameter on a trait method (#1892), in any shape: the trait declaration (#[miniextendr_trait]) and a trait impl. A trait method’s arguments cross the vtable as values its shim converts with TryFromSexp, as for &Dots, which trait methods don’t take either; LazyDots is the generated wrapper’s frame, which has no such value.
refuse_rng_guard_in_trait_method 🔒
Refuse an RngGuard parameter on a trait method (#2002), in any shape: the trait declaration and a trait impl. A trait method’s arguments cross the vtable as values its shim converts with TryFromSexp, and the guard is no R value.
refuse_rng_seed_on_method 🔒
Refuse rng(seed = ..) on an impl or trait method (#2198), spanned on the option: the seed contract is written in the R wrapper of a standalone function or an s3(...) method. meta is rng, followed by its parenthesized options.
rewrite_variadic_dots 🔒
Replace Rust variadic syntax (name: ... / _: ...) with a trailing &miniextendr_api::dots::Dots parameter, so downstream codegen never emits a non-extern variadic Rust fn. Named dots keep the user’s identifier; _: ... binds __miniextendr_dots.
set_check_message 🔒
Record the message = "..." of an inherits / not_inherits / no_na check: the condition message of a failure, used verbatim. It is given once, is not empty, and holds no NUL (an R string cannot).
set_hint_message 🔒
Record the message = "..." of a when(...) hint in inherits(...), under the rules of set_check_message; unlike a check’s message, the hint’s is required.
set_message 🔒
Record value as the message in slot of check(...); if_empty ends the error for an empty message.
type_ends_with 🔒
Check if a type path ends with the given identifier (e.g., “Dots”, “Missing”).
typed_list_on_lazy_dots 🔒
The error for dots = typed_list!(..) on a function whose ... is a LazyDots parameter (#1892): typed_list! validates the forced list(...) of a &Dots parameter, and LazyDots forces nothing. None when the dots are &Dots (or absent). span is the attribute’s, else the parameter’s.
validate_param_type 🔒
Validate a parameter’s type for Missing and Dots conflicts.
validate_per_param_attr_conflicts 🔒
Validate per-parameter attribute conflicts.
validate_postfix 🔒
Parse the value of a name = "..." meta item as a string literal.