rust_eval: Evaluate Rust code

Description Usage Arguments Value Examples

View source: R/eval.R

Description

Compile and evaluate one or more Rust expressions. If the last expression in the Rust code returns a value (i.e., does not end with ;), then this value is returned to R. The value returned does not need to be of type Robj, as long as it can be cast into this type with .into(). This conversion is done automatically, so you don't have to worry about it in your code.

Usage

1
rust_eval(code, env = parent.frame(), ...)

Arguments

code

Input rust code.

env

The R environment in which the Rust code will be evaluated.

...

Other parameters handed off to rust_function().

Value

The return value generated by the Rust code.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
# Rust code without return value, called only for its side effects
rust_eval(
  code = 'rprintln!("hello from Rust!");'
)

# Rust code with return value
rust_eval(
  code = "
    let x = 5;
    let y = 7;
    let z = x * y;
    z // return to R; rust_eval() takes care of type conversion code
 "
)

## End(Not run)

rextendr documentation built on June 15, 2021, 5:06 p.m.