Skip to contents

A package's top-level new_struct(), new_enum(), new_trait(), and impl() calls run when the package is installed, and record themselves in the package's namespace. r8register(), called from the package's .onLoad(), registers them in the session: it checks each declaration again and makes its types, traits, and impls available. Registering a package again replaces its declarations.

Usage

r8register(pkgname = NULL)

Arguments

pkgname

Optional Character: The package; by default, the package whose code calls r8register().

Value

The number of declarations registered, invisibly.

Details

A package with compiled exports, the types and the methods of its Rust code, registers them after its R declarations. Every type of the exports has an R declaration with the same declaration hash, the type of every codec is declared with storage = "rust", and every type declared with storage = "rust" has a codec; otherwise registration signals r8_declaration_error and lists each difference. r8document_rust() generates the R declarations of types declared in Rust. Each impl declaration of the exports is built from its impl entries, grouped by trait and positions.

Types that other packages use

The compiled code of a package holds the declarations of the types of other packages that it was compiled against. It reads the fields of a value of such a type, by name, when every value that the registered declaration admits is one that the compiled declaration admits: fields may be added or reordered, bounds tightened, and rules added. A field removed or renamed, another type or unit, a bound loosened, a rule removed, and another version are a warning of class r8_declaration_warning when the package loads, and an error when its code reads a value. A struct that extends a struct of another package is refused at load when the parent's fields or rules differ.

A package does not change a type that other packages use without coordinating the change with them: see the section "Changing a type that other packages use" of new_struct().

Examples

if (FALSE) { # \dontrun{
.onLoad <- function(libname, pkgname) {
  R8::r8register()
}
} # }