Skip to main content

generate_trait_r6_r_wrapper

Function generate_trait_r6_r_wrapper 

Source
fn generate_trait_r6_r_wrapper(
    type_ident: &Ident,
    trait_name: &Ident,
    methods: &[TraitMethod],
    consts: &[TraitConst],
) -> String
Expand description

Generate R6-style R wrapper code.

R6 classes are defined monolithically (all methods in R6Class()), so trait methods cannot be injected into the class definition. Instead, both instance and static trait methods live in the class-scoped Type$Trait$name namespace (env-style) — the R6 generator object is an environment, so Type$Trait <- new.env() attaches cleanly and Type$Trait$method(x) resolves at the call site.

For impl Counter for SimpleCounter, generates:

  • SimpleCounter$Counter$value(x) – instance method (takes the object)
  • SimpleCounter$Counter$increment(x) – instance method

This class-qualified shape is collision-free by construction: two R6 impls of one trait on different types no longer share an unqualified r6_trait_<Trait>_<method> name (#1115). It also unifies R6 with the Env/S3 namespace shape (#1141) — R6 instance and static methods previously disagreed on shape for no functional reason.