r8rust_signature() writes the Rust function that the body of a typed
function moves into: #[r8::function], the function's name, each parameter
with the Rust type of its declared type, the result's type, the description
as a doc comment, the checks that R8 makes before and after the body as a
comment, and the body todo!(). A vector of doubles, integers, logicals, or
bytes is a slice borrowed for the call, &[f64], and a Vec as a result; a
string is &str, and String as a result; a parameter without a type, or of
a type without a Rust form here, is r8::Sexp, and ... is r8::Dots. The
function then takes the body rust() (new_function()).
Usage
r8rust_signature(f)
# S3 method for class 'r8_rust_text'
print(x, ...)Arguments
- f
A typed function, of
new_function().- x
Character: Rust text.
- ...
Not used.
Examples
op <- options(r8.namespace = "demo")
level <- new_function(
"level",
function(x = arg_vec(type_double()), lo = arg_double(), hi = arg_double()) {
y <- numeric(length(x))
s <- 0
for (i in seq_along(x)) {
s <- min(max(s + x[[i]], lo), hi)
y[[i]] <- s
}
y
},
rules = list(rule(lo <= hi)),
return_type = vec(type_double()),
description = "Holds a running level between `lo` and `hi`."
)
r8rust_signature(level)#> /// Holds a running level between `lo` and `hi`.
#> ///
#> /// R8 checks, before and after the body:
#> /// - `x` is vector of double
#> /// - `lo` is double
#> /// - `hi` is double
#> /// - lo <= hi
#> /// - the result is vector of double
#> #[r8::function]
#> fn level(
#> x: &[f64],
#> lo: f64,
#> hi: f64,
#> ) -> Vec<f64> {
#> todo!()
#> }options(op)