Skip to main content

ParsedImpl

Struct ParsedImpl 

Source
pub struct ParsedImpl {
Show 25 fields pub type_ident: Ident, pub class_system: ClassSystem, pub class_name: Option<String>, pub doc_tags: Vec<String>, pub methods: Vec<ParsedMethod>, pub original_impl: ItemImpl, pub cfg_attrs: Vec<Attribute>, pub vctrs_attrs: VctrsAttrs, pub r6_inherit: Option<String>, pub r6_portable: Option<bool>, pub r6_cloneable: Option<bool>, pub r6_lock_objects: Option<bool>, pub r6_lock_class: Option<bool>, pub s7_parent: Option<String>, pub s7_abstract: bool, pub r_data_accessors: RDataAccessors, pub field_lookup: FieldLookup, pub field_fallback: Option<FieldFallback>, pub strict: bool, pub preconditions: Option<bool>, pub internal: bool, pub noexport: bool, pub constructor_demoted: bool, pub param_warnings: TokenStream, pub class_param_names: HashSet<String>,
}
Expand description

Fully parsed #[miniextendr] impl block, ready for code generation.

Contains the type identity, chosen class system, all parsed methods, the original impl block (with miniextendr attrs stripped for re-emission), and all class-system-specific configuration options. Created by ParsedImpl::parse and consumed by the per-class-system R wrapper generators and generate_method_c_wrapper.

Fields§

§type_ident: Ident

The Rust type name being implemented (e.g., Counter).

§class_system: ClassSystem

Which R class system to generate wrappers for.

§class_name: Option<String>

Optional override for the R class name. When None, uses type_ident as the class name.

§doc_tags: Vec<String>

Roxygen tag lines extracted from /// doc comments on the impl block. Used for class-level documentation (e.g., the R6 class docstring or S3 type description).

§methods: Vec<ParsedMethod>

All parsed methods in this impl block, in source order.

§original_impl: ItemImpl

The original impl block with #[miniextendr] and roxygen attrs stripped. Re-emitted as-is so the Rust compiler sees the actual method implementations.

§cfg_attrs: Vec<Attribute>

#[cfg(...)] attributes from the impl block, propagated to all generated items (C wrappers, R wrapper constants, call def arrays) for conditional compilation.

§vctrs_attrs: VctrsAttrs

vctrs-specific attributes (only used when class_system is Vctrs)

§r6_inherit: Option<String>

R6 parent class name for inheritance (e.g., "ParentClass"). Propagated from ImplAttrs::r6_inherit.

§r6_portable: Option<bool>

R6 portable flag. When Some(true), generates a portable R6 class. Propagated from ImplAttrs::r6_portable.

§r6_cloneable: Option<bool>

R6 cloneable flag. Controls whether $clone() is available on instances. Propagated from ImplAttrs::r6_cloneable.

§r6_lock_objects: Option<bool>

R6 lock_objects flag. When Some(true), prevents adding new fields after creation. Propagated from ImplAttrs::r6_lock_objects.

§r6_lock_class: Option<bool>

R6 lock_class flag. When Some(true), prevents modifying the class definition. Propagated from ImplAttrs::r6_lock_class.

§s7_parent: Option<String>

S7 parent class name for inheritance (e.g., "ParentClass"). Propagated from ImplAttrs::s7_parent.

§s7_abstract: bool

When true, marks this as an abstract S7 class that cannot be instantiated. Propagated from ImplAttrs::s7_abstract.

§r_data_accessors: RDataAccessors

The class-level form of the sidecar #[r_data] fields (r_data_accessors, see RDataAccessors). For R6: active bindings are added via $set("active", ...) after class creation. For S7: properties are spliced from .rdata_properties_{Type} into new_class(). For S3, S4 and env: $ / [[ field methods (field_syntax.rs, #1848).

§field_lookup: FieldLookup

s3(r_data_accessors, lookup = "list"): how the S3 readers look a field up (see FieldLookup).

§field_fallback: Option<FieldFallback>

fallback = "Self::f" (and fallback_names) on an S3, S4 or env class with r_data_accessors: what the readers call for a name no field has (see FieldFallback, #2150).

§strict: bool

Strict conversion mode: methods returning lossy types use checked conversions.

§preconditions: Option<bool>

The impl block’s preconditions / no_preconditions, inherited by every method wrapper. See ImplAttrs::preconditions.

§internal: bool

Mark class as internal: adds @keywords internal, suppresses @export.

§noexport: bool

Suppress @export without adding @keywords internal.

§constructor_demoted: bool

Generate the block as it reads when another impl block of the type has the constructor: the constructor this block would infer stays a static method. expand_impl sets it for the second rendering of a block that infers one (ParsedImpl::inferred_constructor).

§param_warnings: TokenStream

Deprecation warnings for @param tags found on the impl block. Appended to the final TokenStream output.

§class_param_names: HashSet<String>

Parameter names declared via @param in the impl-block doc comments.

For R6 classes, roxygen2 8.0.0 inherits class-level @param tags into all methods. These are the names that appeared in impl-block-level @param tags (extracted before stripping). The R6 generator uses this set to suppress (no documentation available) placeholders for covered params and to emit class-level @param lines in the class header.

Implementations§

Source§

impl ParsedImpl

Source

pub fn parse(attrs: ImplAttrs, item_impl: ItemImpl) -> Result<Self>

Parse an impl block with class system attribute.

Note: Trait impls (impl Trait for Type) are handled by expand_impl before this function is called, so we only handle inherent impls here.

Source

fn reject_unsupported_describe_in(&self) -> Result<()>

Reject a method-level @describeIn that roxygen2 cannot honour (#1590).

roxygen2 lists a @describeIn block in its destination’s “Functions” section through the R object the block documents, and rejects the tag next to @name / @rdname, so MethodDocBuilder drops both for it. That only works where the method’s block sits on a plain R function or S3 method: S3 instance methods (generic.Class), the static methods of S3 / S4 / S7 / vctrs (class_method()), and the S4 constructor (Class()). Everywhere else the block has no object to list:

  • S4 / S7 instance methods are registered by setMethod() / S7::method<- after the if (!exists(...)) generic guard the block is attached to;
  • Env and R6 methods are Class$method <- assignments or live inside R6Class();
  • the S3 / vctrs / S7 constructor is documented by the class block.

There the tag would only earn a roxygen2 warning and a dropped block, so it is a compile error pointing at @rdname instead.

Source

pub fn class_name(&self) -> String

Get the class name (override or type name).

Source

pub fn class_settings(&self) -> String

The class-level settings, written like the attribute, which every impl block of a type must spell the same (#1776): the class system with its options, class = "...", internal / noexport, and the @noRd / @keywords internal tags. They shape the members each block generates, so the wrapper writer refuses blocks that differ. The per-method defaults (strict, preconditions) may differ. A field fallback (fallback = "...", #2150) is no setting: one block has it, as one has the constructor (class_definitions).

Source

pub fn class_definitions(&self) -> Vec<String>

What this impl block has that only one block of a type may: the constructor, S7 properties and the field fallback (#2150). The wrapper writer defines the class from the block that has them (#1776), so the field methods that call the fallback are that block’s; the impl docs of every block merge into the class’s roxygen block (ClassWrapper::class_docs).

Source

pub fn included_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get methods that should be included.

Source

pub fn constructor(&self) -> Option<&ParsedMethod>

The class constructor of this impl block, if it has one: the declared constructor, else the inferred one. Every other receiver-less method is a static method.

Source

pub fn declared_constructor(&self) -> Option<&ParsedMethod>

The constructor the block declares: the method marked #[miniextendr(<system>(constructor))] (at most one, check_constructor_markers), else a receiver-less new returning Self. For vctrs, new may return anything: the canonical vctrs constructor returns the vector payload (e.g. Vec<f64>), which vctrs::new_vctr() then wraps; returning Self would produce an ExternalPtr that new_vctr can’t accept as .data.

Source

pub fn constructor_candidates(&self) -> impl Iterator<Item = &ParsedMethod>

The methods that could be the class constructor: the receiver-less methods returning Self (bare Self, as ParsedMethod::returns_self reads it, so not Result<Self, E> or Option<Self>), other than the declared constructor and an S7 convert_from method, in source order. Without a declared constructor, the one candidate of a type is its constructor; with several, the type needs a declared one. None for vctrs, whose constructor returns the vector payload rather than Self.

Source

pub fn inferred_constructor(&self) -> Option<&ParsedMethod>

The constructor this block infers: its one candidate, whatever its name, when it declares no constructor. None in the rendering for a type whose constructor another impl block declares (constructor_demoted). The wrapper writer decides per type which rendering it writes.

Source

fn is_method_constructor(&self, m: &ParsedMethod) -> bool

Whether m is the class constructor.

Source

fn static_doc_tags<'a>( &self, m: &'a ParsedMethod, call: &str, constructor: &str, params: bool, ) -> Cow<'a, [String]>

The roxygen tags of the static method m, called as call (e.g. Counter$from_value()). The constructor under its own name (constructor_keeps_own_name) points at the class constructor constructor (e.g. Counter$new()) instead of repeating its docs, keeping the method’s @noRd / @keywords, and its @param tags when params (roxygen2 merges them with the class constructor’s).

Source

fn check_constructor_markers(&self) -> Result<()>

Refuse two methods marked #[miniextendr(<system>(constructor))]: a class has one constructor.

Source

pub fn public_instance_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get public instance methods (have env, not private, not active, not an R6 finalizer or deep_clone handler).

Source

pub fn private_instance_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get private instance methods (have env, private visibility, not active).

Source

pub fn active_instance_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get active binding getter methods for R6 (have env, marked active, not setter). Active bindings provide property-like access (obj$name instead of obj$name()).

Source

pub fn active_setter_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get active binding setter methods for R6 (have env, marked as r6_setter).

Source

pub fn find_setter_for_prop(&self, prop_name: &str) -> Option<&ParsedMethod>

Find the setter method for a given property name.

Source

pub fn instance_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get instance methods (have env) - includes both public and private.

Source

pub fn static_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get static methods (no env, not finalizer): the receiver-less methods other than the constructor, and the constructor too when its R name isn’t new (constructor_keeps_own_name).

Source

fn constructor_keeps_own_name(&self, m: &ParsedMethod) -> bool

Whether the constructor m is also a static method under its own name: Type$from_value() next to Type$new(), Type_from_value() next to Type(), type_from_value() next to new_type(). A constructor named new has no second name, and a vctrs constructor returns the vector payload, which only new_<class>() classes.

Source

pub fn as_coercion_methods(&self) -> impl Iterator<Item = &ParsedMethod>

Get methods with #[miniextendr(as = "...")] attribute.

These generate S3 methods for R’s as.<class>() generics like as.data.frame.MyType, as.list.MyType, etc.

Source

pub fn finalizer(&self) -> Option<&ParsedMethod>

Get the finalizer method, if any.

Trait Implementations§

Source§

impl Debug for ParsedImpl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ParsedImplExt for ParsedImpl

Source§

fn constructor_context(&self) -> Option<MethodContext<'_>>

Create a MethodContext for the constructor method, if one exists.
Source§

fn instance_method_contexts(&self) -> impl Iterator<Item = MethodContext<'_>>

Iterate over all instance methods (public + private + active) as MethodContext.
Source§

fn static_method_contexts(&self) -> impl Iterator<Item = MethodContext<'_>>

Iterate over static (non-receiver) methods as MethodContext.
Source§

fn public_instance_method_contexts( &self, ) -> impl Iterator<Item = MethodContext<'_>>

Iterate over public instance methods as MethodContext (for R6 public list).
Source§

fn private_instance_method_contexts( &self, ) -> impl Iterator<Item = MethodContext<'_>>

Iterate over private instance methods as MethodContext (for R6 private list).
Source§

fn active_instance_method_contexts( &self, ) -> impl Iterator<Item = MethodContext<'_>>

Iterate over active binding methods as MethodContext (for R6 active list).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 656 bytes