pub unsafe fn extract_arg<T>(
argc: i32,
argv: *const SEXP,
index: usize,
name: &str,
) -> TExpand 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
T- Target Rust type (must implementTryFromSexp)
§Arguments
argc- Number of argumentsargv- Pointer to argument arrayindex- Index of argument to extractname- Name of argument (for error messages)
§Returns
The converted argument value.
§Safety
argvmust point to at leastargcvalid 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") };