Skip to main content

generate_r6_class

Function generate_r6_class 

Source
pub fn generate_r6_class(parsed_impl: &ParsedImpl) -> ClassWrapper
Expand description

Generates the R wrapper of an R6-style class, in the parts the wrapper writer merges per type (super::ClassWrapper, #1776).

Produces an R6::R6Class(...) core definition followed by per-method $set() blocks (see the module docs for the full $set-form shape, #369):

  • initialize method (inline in public): calls the Rust constructor, or accepts a pre-made .ptr when a factory returns Self; a class without a constructor accepts only the .ptr and raises the no-constructor error without one
  • Public methods: one ClassName$set("public", "name", function(...) {...}) block per &self/&mut self instance method, each with its own roxygen
  • Private methods: one ClassName$set("private", "name", function(...) {...}) block per method marked with #[miniextendr(private)]
  • Active bindings: one ClassName$set("active", "name", function(...) {...}) block per getter/setter property (#[miniextendr(r6(prop = "..."))])
  • Private .ptr field (inline in private): holds the ExternalPtr to the Rust struct
  • Finalizer ($set("private", "finalize", ...)): optional destructor called when the R6 object is garbage-collected
  • Deep clone ($set("private", "deep_clone", ...)): optional custom clone logic via #[miniextendr(r6(deep_clone))]
  • Static methods: emitted as ClassName$method_name <- function(...) outside the class
  • Class options: lock_objects, lock_class, cloneable, portable, inherit

Also generates roxygen2 documentation blocks for the class, its methods, and active bindings.

The R6Class() core is the head; the $set() blocks and the static methods are the members; the sidecar active bindings and $lock() are the tail, after every block’s $set().