Skip to main content

generate_vctrs_r_wrapper

Function generate_vctrs_r_wrapper 

Source
pub fn generate_vctrs_r_wrapper(parsed_impl: &ParsedImpl) -> String
Expand description

Generates the complete R wrapper string for a vctrs-compatible S3 class.

This is used when an impl block is annotated with #[miniextendr(vctrs)]. Unlike the #[derive(Vctrs)] macro (which generates standalone S3 methods from struct attributes), this generator produces class wrappers from impl block methods.

Produces the following R code:

  • Constructor: new_<class>(...) that calls the Rust new constructor, then wraps the result with vctrs::new_vctr(), vctrs::new_rcrd(), or vctrs::new_list_of() depending on the VctrsKind
  • vec_ptype_abbr.<class>: compact abbreviation for printing (if abbr is specified)
  • vec_ptype2.<class>.<class>: self-coercion prototype (returns empty typed vector)
  • vec_cast.<class>.<class>: identity cast (returns x unchanged)
  • Instance methods: S3 generics + <generic>.<class> methods, with support for vctrs protocol overrides via #[miniextendr(vctrs_protocol = "...")] and double-dispatch class suffixes via #[miniextendr(class = "...")]
  • Static methods: regular functions named <class>_<method>(...)

Roxygen2 documentation and @importFrom vctrs ... tags are generated automatically. A class-level @noRd (or a plain noexport without internal) suppresses the Rd contribution of every block — self-coercion methods, instance-method generics, and instance/static method docs all collapse to @noRd (#1180), like the other five class-system generators. S3 S3method() dispatch registration (@method + @export) is kept unconditionally: vctrs generics dispatch from the vctrs namespace, so an unregistered method would leave even a gated class non-functional (and roxygen2 warns on any recognized-but-unregistered S3 method).