Skip to main content

extract_arg

Function extract_arg 

Source
pub unsafe fn extract_arg<T>(
    argc: i32,
    argv: *const SEXP,
    index: usize,
    name: &str,
) -> T
where T: TryFromSexp, T::Error: Display,
Expand description

Extract and convert an argument from argv with bounds checking.

Checks that index < argc before extracting, and provides a helpful error message if out of bounds.

§Type Parameters

§Arguments

  • argc - Number of arguments
  • argv - Pointer to argument array
  • index - Index of argument to extract
  • name - Name of argument (for error messages)

§Returns

The converted argument value.

§Safety

  • argv must point to at least argc valid SEXPs
  • Must be called on R’s main thread

§Errors

Calls rf_error if:

  • index >= argc (missing argument)
  • Conversion fails

§Example

// In a method shim for fn foo(&self, x: i32, y: String)
let x: i32 = unsafe { extract_arg(argc, argv, 0, "x") };
let y: String = unsafe { extract_arg(argc, argv, 1, "y") };