Skip to main content

Module r_preconditions

Module r_preconditions 

Source
Expand description

R-side precondition generation for type checking.

Generates stopifnot() checks in R wrapper functions that run BEFORE the .Call() boundary. This gives users clear, idiomatic R error messages with proper stack traces instead of Rust panic messages.

Each assertion checks ONE thing with a precise error message:

add <- function(a, b) {
  stopifnot(
    "'a' must be numeric, logical, or raw" = is.numeric(a) || is.logical(a) || is.raw(a),
    "'a' must have length 1" = length(a) == 1L,
    "'b' must be numeric, logical, or raw" = is.numeric(b) || is.logical(b) || is.raw(b),
    "'b' must have length 1" = length(b) == 1L
  )
  .Call(C_add, .call = match.call(), a, b)
}

StructsΒ§

FallbackParam
A parameter whose Rust type is not in the static type table.
PreconditionOutput
Output of precondition analysis for a function’s parameters.
RAssertion πŸ”’
A single stopifnot() assertion: "message" = condition.

EnumsΒ§

RTypeCheck πŸ”’
Classification of an R-side type check for a function parameter.

FunctionsΒ§

build_precondition_checks
Build precondition checks for a function’s parameters.
extract_single_generic_arg πŸ”’
Extract the single generic type argument from a path segment.
is_skip_type πŸ”’
Returns true for types that should never get a fallback precheck.
needs_fallback πŸ”’
Returns true if a type is unknown to the static type table and should be recorded as a fallback parameter.
numeric_type_check πŸ”’
Build the R expression for the numeric type predicate.
r_check_for_reference πŸ”’
Map a reference type to its R-side type check.
r_check_for_type πŸ”’
Map a Rust type to its R-side type check, if applicable.
r_check_for_type_path πŸ”’
Map a syn::TypePath to its R-side type check.
r_check_for_vec_element πŸ”’
Map a Vec<T> or &[T] element type to the appropriate vector type check.