Skip to main content

Module no_constructor

Module no_constructor 

Source
Expand description

MXL121: a class R code can never create.

A type’s objects come from its constructor, from the functions that return one, or from pointers the crate builds itself. The constructor is the method marked #[miniextendr(<system>(constructor))], else the receiver-less method returning bare Self the macro infers, in any of the type’s inherent #[miniextendr] impl blocks. A factory is any #[miniextendr] fn or method returning T, Self or ExternalPtr<T>, bare or inside Result / Option (returned_types in the index). A hand-built pointer is an ExternalPtr::new(T { .. }) / ExternalPtr::new(T(..)), also through a local bound earlier in the same function body (let x = T { .. }, let x = T(..), let x: T = ..), or an ExternalPtr<T> written as a type or turbofish, anywhere in the crate, #[miniextendr] or not (hand_built_types): a wrapper whose hand-written IntoR builds the pointer is a factory too. Without any of these, every method of the class needs an object R code has no way to get.

The type’s own methods taking self don’t count: they need an object already. Nor do parameters: the caller has the object. vctrs classes are skipped: the package builds their vectors in R from the payload, not from a T. ExternalPtr::new(value) of a value from a call whose type isn’t written (let record = make_record(inner); ExternalPtr::new(record)), or of a value from another function, is invisible; writing the type (let record: T = ..) or // mxl::allow(MXL121) covers it. So is code inside macro calls (vec![..]), which syn does not parse.

Functions§

check