Skip to contents

Writes R/r8-types.R, the R declaration of each type and trait that a package declares in Rust and lists in its compiled exports: one new_struct() or new_enum() call per type, Rust-stored types with storage = "rust", and one generic() or new_trait() call per trait, with a binding for each of a trait's generics, with roxygen comments from the Rust doc comments. The R code of the package then has the type objects, their constructors, the generics, and their declarations at install, before the shared object loads, and r8register() checks at load that each R declaration has the hash of its Rust declaration.

Usage

r8document_rust(path = ".", check = FALSE)

Arguments

path

Character: The package's root directory.

check

Logical: Compare the rendered file with R/r8-types.R and signal an error when they differ, without writing.

The file is current when its code and comments, token by token, equal the rendered file's; a formatter that changes only the layout, such as air, leaves it current, and the generator does not rewrite it.

Value

The path of R/r8-types.R, invisibly.

Details

A dyn() field names its trait's object. A trait that the package declares in R is bound to its name there, in a file that precedes R/r8-types.R in the Collate field of DESCRIPTION. A trait of another package is its exported object.

The generator reads the IR document from the compiled shared object, src/<package><dynlib.ext>, which it loads with dyn.load() and unloads when it finishes; the package itself is not loaded, so the generator runs while its R declarations are absent or differ from the Rust ones. Before it writes, it declares the rendered file in the session and compares the declaration hash of every type with the exports' hash, so it runs in an R session of its own, without the package loaded: Rscript -e "R8::r8document_rust()", after pkgbuild::compile_dll() and before roxygen.

Examples

if (FALSE) { # \dontrun{
pkgbuild::compile_dll()
system2("Rscript", c("-e", shQuote("R8::r8document_rust()")))
roxygen2::roxygenise()
} # }