pub fn generate_env_class(parsed_impl: &ParsedImpl) -> ClassWrapperExpand description
Generates the R wrapper of an environment-based class, in the parts the
wrapper writer merges per type (super::ClassWrapper, #1776).
Produces an R environment object (new.env(parent = emptyenv())) that serves as a
class namespace, with methods attached as ClassName$method_name. This pattern
supports both inherent methods and trait namespace dispatch via $/[[.
The generated code includes:
- Class environment:
ClassName <- new.env(parent = emptyenv()) - Constructor:
ClassName$new(...)that calls the Rustnewfunction, setsclass(self) <- "ClassName", and returns the ExternalPtr asself - Instance methods:
ClassName$method(...)whose bodies read a freeself, which$dispatch binds in a fresh environment over the method’s own - Static methods:
ClassName$method(...)that call Rust directly $.ClassNameS3 method: dispatchesobj$method(...)by looking up the method in the class environment, binding.mx_selffor instance methods, and supporting trait namespace environments (nested envs with.__mx_instance__attributes), through the package’s shared.miniextendr_env_methodhelper[[.ClassName: the same lookup, withexact(ignored) and a...that refuses every argument (#2174)- With
env(r_data_accessors): a field branch at the top of$.ClassName(a#[r_data]field wins over a method of the same name),.DollarNames.ClassName(the fields, then the methods; #1885), and, unless the getters-onlyr_data_accessors = "get",$<-.ClassNamewith its[[<-.ClassNamealias (field_syntax.rs, #1848)
Roxygen2 documentation is generated for the class, each method, and the
dispatch methods, with appropriate @export/@keywords internal/@noRd tags.
The class environment and constructor are the head; the instance and static methods are the members; the dispatch methods are the tail.