Skip to main content

generate_vctrs_class

Function generate_vctrs_class 

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

Generates the R wrapper of a vctrs-compatible S3 class, in the parts the wrapper writer merges per type (super::ClassWrapper, #1776).

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)
  • Static methods: regular functions named <class>_<method>(...), or <protocol>.<class> S3 methods with #[miniextendr(vctrs(<protocol>))] (instance methods are refused, MXL120)

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 and 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).

The constructor, vec_ptype_abbr and the self-coercion methods are the head; the static methods and protocol methods are the members.