Skip to main content

ParsedMethod

Struct ParsedMethod 

Source
pub struct ParsedMethod {
    pub visibility_marker: Option<bool>,
    pub return_wrap: Option<ReturnWrap>,
    pub ident: Ident,
    pub env: ReceiverKind,
    pub sig: Signature,
    pub param_markers: Vec<(String, Vec<ParamMarker>)>,
    pub vis: Visibility,
    pub doc_tags: Vec<String>,
    pub method_attrs: MethodAttrs,
    pub param_defaults: HashMap<String, String>,
    pub has_dots: bool,
    pub rng_guard: Option<usize>,
}
Expand description

Parsed method from an impl block.

§Default Parameters

Default parameters are specified using method-level syntax:

  • #[miniextendr(defaults(param = "value", ...))] on the method

Note: Parameter-level #[miniextendr(default = "...")] syntax is only supported for standalone functions, not impl methods (Rust language limitation).

Defaults cannot be specified for self parameters (compile error).

Fields§

§visibility_marker: Option<bool>

Return-type visibility marker (#1213): Some(true) for -> Invisible<T>, Some(false) for -> Visible<T>. The marker is peeled from Self::sig at parse time, so every return-shape predicate sees T; the C wrapper unwraps the newtype before conversion.

§return_wrap: Option<ReturnWrap>

Explicit target class wrapping, shared by marker and attribute spellings.

§ident: Ident

The method’s name (e.g., new, get, set_value).

§env: ReceiverKind

How this method receives self: &self, &mut self, by value, or not at all (static).

§sig: Signature

Method signature with the self receiver stripped. Used for C wrapper generation where self is handled separately as a SEXP parameter. The parameter markers (Checked<T> / Unchecked<T>, #1566) are peeled from it, as the visibility marker is from the output: every R-side consumer and the conversion see the inner type.

§param_markers: Vec<(String, Vec<ParamMarker>)>

The parameter markers peeled from Self::sig (Rust name → markers, outermost first): the C wrapper wraps the converted value in them before the call.

§vis: Visibility

Rust visibility of the method. Non-pub methods become private in R6; only pub methods get @export in R wrappers.

§doc_tags: Vec<String>

Roxygen tag lines extracted from Rust doc comments

§method_attrs: MethodAttrs

Per-method attributes for class system overrides. Also carries the match_arg(...) / choices(...) / several_ok parameter annotations via its per_param_match_arg / per_param_choices / per_param_several_ok fields — see MethodAttrs for the parsing surface.

§param_defaults: HashMap<String, String>

Parameter default values from #[miniextendr(defaults(...))], keyed by Rust name; the R wrapper keys them by formal (Formals::rekey).

§has_dots: bool

Whether this method accepts dots, either from raw ... rewritten to &Dots or from an explicit &Dots parameter, anywhere.

§rng_guard: Option<usize>

Where the &RngGuard parameter (#2002) sat among the parameters of Self::sig, which no longer holds it: it is no R formal, and the C wrapper passes the rng wrapper’s guard at that position.

Implementations§

Source§

impl ParsedMethod

Source

fn validate_method_attrs( attrs: &MethodAttrs, class_system: ClassSystem, span: Span, ) -> Result<()>

Validate method attributes for the given class system. Returns an error if unsupported attributes are used.

Source

fn parse_method_attrs(attrs: &[Attribute]) -> Result<MethodAttrs>

Parse method attributes in #[miniextendr(class_system(…))] format.

Supported formats:

  • #[miniextendr(r6(ignore, constructor, finalize, private, generic = "...")]
  • #[miniextendr(s3(ignore, constructor, generic = "..."))]
  • #[miniextendr(s7(ignore, constructor, generic = "..."))]
  • etc.
Source

fn detect_env(sig: &Signature) -> ReceiverKind

Detect the ReceiverKind from a method’s function signature.

Inspects the first parameter to determine whether this is a static function (None), immutable borrow (Ref), mutable borrow (RefMut), consuming method (Value), or handle receiver (ExternalPtrRef, ExternalPtrMut, ExternalPtrValue). Handles both standard receivers (&self, &mut self) and typed receivers (self: &Self, self: ExternalPtr<Self>, etc.).

Source

fn sig_without_env(sig: &Signature) -> Signature

Create a copy of the method signature with the self receiver removed.

The C wrapper receives self as a separate SEXP argument and extracts it from an ErasedExternalPtr, so the receiver must not appear in the parameter list used for SEXP-to-Rust conversion codegen.

Source

pub fn from_impl_item(item: &mut ImplItemFn, class_page: RdPage) -> Result<Self>

Parse a method from an impl item.

Regular doc comments are auto-converted to @description for all class systems. class_page is whether the class block renders a help page: the method’s docs go nowhere else when it does not.

Source

pub fn should_include(&self) -> bool

Returns true if this method should be included in the class.

Source

pub fn is_private(&self) -> bool

Returns true if this method should be private in R6. Inferred from Rust visibility: anything not pub is private.

Source

pub fn is_constructor(&self) -> bool

Returns true if this is likely a constructor. Inferred from: no env + named “new” + returns Self.

Source

pub fn is_finalizer(&self) -> bool

Returns true if this method is the R6 finalizer.

Only the explicit #[miniextendr(r6(finalize))] marker qualifies. It used to be inferred from “takes self by value and does not return Self”, which silently hid consuming methods on every class system (#1432).

Source

pub fn is_active(&self) -> bool

Returns true if this method should be an R6 active binding. Active bindings provide property-like access (obj$name instead of obj$name()).

Source

pub fn r_method_name(&self) -> String

R-facing method name.

Returns r_name if set, otherwise the Rust ident with postfix appended when given, otherwise the Rust ident as a string.

Source

pub fn c_wrapper_ident(&self, type_ident: &Ident) -> Ident

C wrapper identifier for this method.

Format: C_{crate}_{Type}__{method} — crate-prefixed for webR cross-package symbol uniqueness (#1273). Unique per type: two impl blocks of one type can’t both define a method (E0592).

Source

pub fn formals(&self) -> Formals

The R formal of each parameter (#1842), from the method’s formal(p = "...").

Source

pub fn lifecycle_prelude(&self, what: &str) -> Option<String>

Generate lifecycle prelude R code for this method, if lifecycle is specified.

The what parameter describes the method in the format appropriate for the class system:

  • Env/R6: "Type$method()"
  • S3: "method.Type()"
  • S7: "method()“ (dispatched generics)
Source

pub fn returns_self(&self) -> bool

Returns true if this method returns Self.

Source

pub fn returns_result_self(&self) -> bool

Returns true if this method returns Result<Self, E> — a fallible constructor-shaped method (e.g. from_r, try_new). On the R side this is treated exactly like a bare Self return (wrapped class object via crate::ReturnStrategy::for_method); the C wrapper still raises on Err via the normal Result error path (see crate::c_wrapper_builder::ReturnHandling::ResultExternalPtr).

Source

pub fn returns_option_self(&self) -> bool

Returns true if this method returns Option<Self> — a lookup-shaped fallible constructor (e.g. try_find). On the R side this is treated exactly like a bare Self return (wrapped class object via crate::ReturnStrategy::for_method); the C wrapper still raises on None via the normal Option error path (see crate::c_wrapper_builder::ReturnHandling::OptionExternalPtr). Symmetric with Self::returns_result_self.

Source

pub fn returns_other_class(&self) -> Option<Ident>

Returns the bare type name when this method returns a type that may be a different registered ExternalPtr-backed class.

This is deliberately syntactic and conservative about primitives and common containers. The write-time wrapper resolver checks the complete class registry, so an unregistered capitalized type falls back to the direct .val return.

Four shapes are recognized:

  • A bare capitalized path, e.g. -> Board.
  • Option<T> where T is a bare capitalized path. The C wrapper converts the whole Option (ReturnHandling::OptionIntoR, as a function’s), so .val is a bare pointer for Some, wrapped as in the bare-class case, and NULL for None, which the wrap passes through (returns_option).
  • Result<T, E> where T is a bare capitalized path and E is not (). Result<T, ()> is excluded: the unit-error sentinel maps to ReturnHandling::ResultNullOnErr, where .val can be NULL on Ok, and wrapping NULL in a class constructor would break.
  • ExternalPtr<T> (the explicit-handle spelling, #1375), including through the Option/Result wrappers above (e.g. Option<ExternalPtr<Board>>) — IntoR for ExternalPtr<T> already produces a bare EXTPTRSXP .val, identical in shape to the bare T case, so inner_class_ident peels through it to the same wrapped name.

Option<Self> / Result<Self, _> are excluded here too (the inner ident is Self) — ReturnStrategy::for_method checks returns_result_self() / returns_option_self() before this method, so those already take the ReturnSelf path regardless. List-shaped returns (Vec<Class> and its Option/Result wrappers) are handled separately by returns_other_class_list; any other nested container is not recognized: the inner type must be a bare path (or an ExternalPtr<...> wrapping one) with no other path arguments.

Source

pub fn returns_other_class_list(&self) -> Option<Ident>

Returns the bare element type name when this method returns a list of values that may be a different registered ExternalPtr-backed class.

The list-shaped sibling of returns_other_class (#1284). Like the scalar detector it is deliberately syntactic: the write-time resolver checks the complete class registry, and an unregistered element type falls back to the bare list of external pointers.

Four shapes are recognized (the element type must pass the same bare capitalized-path filter as the scalar case, optionally through a trailing ExternalPtr<...> segment):

  • Vec<Class> — the C wrapper converts via IntoR into a VECSXP of external pointers (the IntoRVecElement impl emitted by #[derive(ExternalPtr)]), so .val is a bare list.
  • Option<Vec<Class>> — the C wrapper converts the whole Option (ReturnHandling::OptionIntoR), so .val is the same bare list for Some and NULL for None, which the lapply wrap passes through rather than turning it into list().
  • Result<Vec<Class>, E> where E is not () — the C wrapper raises on Err (ReturnHandling::ResultIntoR); same bare list on Ok. Result<Vec<Class>, ()> is excluded: the unit-error sentinel maps to ReturnHandling::ResultNullOnErr, where .val can be NULL, and lapply(NULL, ...) would silently turn that NULL into list().
  • Vec<ExternalPtr<Class>> (the explicit-handle spelling, #1375), including through the Option/Result wrappers above — the element filter is inner_class_ident, which peels the ExternalPtr segment, so this resolves identically to Vec<Class>.

Not recognized (deliberately):

  • Vec<Self> — ParsedMethod doesn’t carry the enclosing impl’s type ident, so this detector can’t name the target class. Handled instead by returns_self_list, a boolean sibling that ReturnStrategy::for_method treats the same as this method returning Some; MethodReturnBuilder::with_return_class_from_method substitutes the actual name using the type_ident every call site already has in scope (#1375).
  • Vec<Option<Class>> — has no IntoR impl (the Vec<Option<T>> blanket slot is occupied by the newtype funnel) and would need a NULL-tolerant per-element wrap; tracked as a follow-up.
Source

pub(crate) fn vec_inner_class_ident(ty: &Type) -> Option<Ident>

Applies inner_class_ident to the element type of a Vec<T>: ty must be a Vec path whose single type argument is either a bare syn::Type::Path or an ExternalPtr<...> wrapping one (peeled by inner_class_ident, #1375).

Source

fn class_ident_from_ident(ident: &Ident) -> Option<Ident>

Shared name filter for returns_other_class: rejects Self, builtin scalar/string names, and known container names; accepts only idents starting with an ASCII-uppercase letter.

Source

pub(crate) fn inner_class_ident(ty: &Type) -> Option<Ident>

Applies class_ident_from_ident to a container’s inner type argument (e.g. the T in Option<T>).

Two shapes qualify:

  • A bare syn::Type::Path with no path arguments of its own — this is what excludes nested containers like Option<Vec<T>>, whose inner Vec<T> carries PathArguments::AngleBracketed.
  • ExternalPtr<T> (#1375): the explicit-handle spelling wraps identically to a bare T at the value level (IntoR for ExternalPtr<T> already produces a bare EXTPTRSXP), so the handle is peeled with the same helper the explicit wrap path uses.
Source

pub fn returns_self_list(&self) -> bool

Returns true when this method returns Vec<Self> — the receiver-class sibling of returns_other_class_list that this syntactic detector can’t resolve to a name on its own, because ParsedMethod doesn’t carry the enclosing impl’s type ident (#1375).

ReturnStrategy::for_method treats a true result exactly like returns_other_class_list() returning Some (both select ReturnOtherClassList); MethodReturnBuilder::with_return_class_from_method does the actual name substitution, using the type_ident every class-system generator already has in scope — preferred over widening ParsedMethod to carry the impl ident (see that method’s rustdoc for why: the substituted name must be the Rust type name, which is not always the same string as the R-facing class name).

Same three container shapes as returns_other_class_list, with the element check inverted (the element must be Self, not be excluded for being Self): Vec<Self>, Option<Vec<Self>>, Result<Vec<Self>, E> (E not ()).

Source

fn is_vec_of_self(ty: &Type) -> bool

True when ty is Vec<Self> — a bare Self ident, matching the looser ident-only check returns_self uses (no generic-argument check on Self itself, which cannot carry any in this position).

Source

pub fn returns_self_ref(&self) -> bool

Returns true if this method returns a reference to Self (&Self or &mut Self) — the idiomatic Rust in-place builder signature.

These methods mutate (&mut self) or read (&self) the receiver and return a borrow of the same value so calls can be chained in Rust (b.set_a(1).set_b(2)). On the R side this maps to a pipe-friendly free function (S3) / chainable instance method that returns the same ExternalPtr handle, so the R idiom obj |> set_a(1) |> set_b(2) works with in-place value semantics (no clone). See crate::c_wrapper_builder::ReturnHandling::SelfHandle.

Source

fn is_self_ref_type(ty: &Type) -> bool

&Self / &mut Self test shared by the bare and wrapped forms.

Source

fn wrapped_output_arg(&self, wrapper: &str) -> Option<&Type>

First type argument of Wrapper<..> when the output’s last path segment is wrapper (Result / Option).

Source

pub fn returns_result_self_ref(&self) -> bool

-> Result<&Self, E> / -> Result<&mut Self, E>: a fallible in-place builder step (#1433). Ok hands back the same handle like Self::returns_self_ref; Err raises through the normal Result error path.

Source

pub fn returns_option_self_ref(&self) -> bool

-> Option<&Self> / -> Option<&mut Self>: the Option sibling of Self::returns_result_self_ref; None returns NULL and leaves the object as it was.

Source

pub fn returns_option(&self) -> bool

-> Option<..>: .val is NULL for None, so a cross-class wrap of the value has to let NULL through.

Source

pub fn returns_unit(&self) -> bool

Returns true if this method has no return type (returns unit ()).

Source

pub fn is_invisible(&self) -> bool

Whether the R wrapper returns this method’s value with invisible() (#1213): an Invisible<T> return-type marker or the invisible method option. Methods are visible by default, including the receiver-returning chainable tails.

Trait Implementations§

Source§

impl Debug for ParsedMethod

Source§

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

Formats the value using the given formatter. Read more

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: 1696 bytes