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: IdentThe method’s name (e.g., new, get, set_value).
env: ReceiverKindHow this method receives self: &self, &mut self, by value, or not at all (static).
sig: SignatureMethod 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: VisibilityRust visibility of the method. Non-pub methods become private in R6;
only pub methods get @export in R wrappers.
Roxygen tag lines extracted from Rust doc comments
method_attrs: MethodAttrsPer-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: boolWhether 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
impl ParsedMethod
Sourcefn validate_method_attrs(
attrs: &MethodAttrs,
class_system: ClassSystem,
span: Span,
) -> Result<()>
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.
Sourcefn parse_method_attrs(attrs: &[Attribute]) -> Result<MethodAttrs>
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.
Sourcefn detect_env(sig: &Signature) -> ReceiverKind
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.).
Sourcefn sig_without_env(sig: &Signature) -> Signature
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.
Sourcepub fn from_impl_item(item: &mut ImplItemFn, class_page: RdPage) -> Result<Self>
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.
Sourcepub fn should_include(&self) -> bool
pub fn should_include(&self) -> bool
Returns true if this method should be included in the class.
Sourcepub fn is_private(&self) -> bool
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.
Sourcepub fn is_constructor(&self) -> bool
pub fn is_constructor(&self) -> bool
Returns true if this is likely a constructor. Inferred from: no env + named “new” + returns Self.
Sourcepub fn is_finalizer(&self) -> bool
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).
Sourcepub fn is_active(&self) -> bool
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()).
Sourcepub fn r_method_name(&self) -> String
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.
Sourcepub fn c_wrapper_ident(&self, type_ident: &Ident) -> Ident
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).
Sourcepub fn formals(&self) -> Formals
pub fn formals(&self) -> Formals
The R formal of each parameter (#1842), from the method’s
formal(p = "...").
Sourcepub fn lifecycle_prelude(&self, what: &str) -> Option<String>
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)
Sourcepub fn returns_self(&self) -> bool
pub fn returns_self(&self) -> bool
Returns true if this method returns Self.
Sourcepub fn returns_result_self(&self) -> bool
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).
Sourcepub fn returns_option_self(&self) -> bool
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.
Sourcepub fn returns_other_class(&self) -> Option<Ident>
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>whereTis a bare capitalized path. The C wrapper converts the wholeOption(ReturnHandling::OptionIntoR, as a function’s), so.valis a bare pointer forSome, wrapped as in the bare-class case, andNULLforNone, which the wrap passes through (returns_option).Result<T, E>whereTis a bare capitalized path andEis not().Result<T, ()>is excluded: the unit-error sentinel maps toReturnHandling::ResultNullOnErr, where.valcan beNULLonOk, and wrappingNULLin a class constructor would break.ExternalPtr<T>(the explicit-handle spelling, #1375), including through theOption/Resultwrappers above (e.g.Option<ExternalPtr<Board>>) —IntoR for ExternalPtr<T>already produces a bareEXTPTRSXP.val, identical in shape to the bareTcase, soinner_class_identpeels 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.
Sourcepub fn returns_other_class_list(&self) -> Option<Ident>
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 viaIntoRinto aVECSXPof external pointers (theIntoRVecElementimpl emitted by#[derive(ExternalPtr)]), so.valis a bare list.Option<Vec<Class>>— the C wrapper converts the wholeOption(ReturnHandling::OptionIntoR), so.valis the same bare list forSomeandNULLforNone, which thelapplywrap passes through rather than turning it intolist().Result<Vec<Class>, E>whereEis not()— the C wrapper raises onErr(ReturnHandling::ResultIntoR); same bare list onOk.Result<Vec<Class>, ()>is excluded: the unit-error sentinel maps toReturnHandling::ResultNullOnErr, where.valcan beNULL, andlapply(NULL, ...)would silently turn thatNULLintolist().Vec<ExternalPtr<Class>>(the explicit-handle spelling, #1375), including through theOption/Resultwrappers above — the element filter isinner_class_ident, which peels theExternalPtrsegment, so this resolves identically toVec<Class>.
Not recognized (deliberately):
Vec<Self>—ParsedMethoddoesn’t carry the enclosing impl’s type ident, so this detector can’t name the target class. Handled instead byreturns_self_list, a boolean sibling thatReturnStrategy::for_methodtreats the same as this method returningSome;MethodReturnBuilder::with_return_class_from_methodsubstitutes the actual name using thetype_identevery call site already has in scope (#1375).Vec<Option<Class>>— has noIntoRimpl (theVec<Option<T>>blanket slot is occupied by the newtype funnel) and would need a NULL-tolerant per-element wrap; tracked as a follow-up.
Sourcepub(crate) fn vec_inner_class_ident(ty: &Type) -> Option<Ident>
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).
Sourcefn class_ident_from_ident(ident: &Ident) -> Option<Ident>
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.
Sourcepub(crate) fn inner_class_ident(ty: &Type) -> Option<Ident>
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::Pathwith no path arguments of its own — this is what excludes nested containers likeOption<Vec<T>>, whose innerVec<T>carriesPathArguments::AngleBracketed. ExternalPtr<T>(#1375): the explicit-handle spelling wraps identically to a bareTat the value level (IntoR for ExternalPtr<T>already produces a bareEXTPTRSXP), so the handle is peeled with the same helper the explicitwrappath uses.
Sourcepub fn returns_self_list(&self) -> bool
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 ()).
Sourcefn is_vec_of_self(ty: &Type) -> bool
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).
Sourcepub fn returns_self_ref(&self) -> bool
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.
Sourcefn is_self_ref_type(ty: &Type) -> bool
fn is_self_ref_type(ty: &Type) -> bool
&Self / &mut Self test shared by the bare and wrapped forms.
Sourcefn wrapped_output_arg(&self, wrapper: &str) -> Option<&Type>
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).
Sourcepub fn returns_result_self_ref(&self) -> bool
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.
Sourcepub fn returns_option_self_ref(&self) -> bool
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.
Sourcepub fn returns_option(&self) -> bool
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.
Sourcepub fn returns_unit(&self) -> bool
pub fn returns_unit(&self) -> bool
Returns true if this method has no return type (returns unit ()).
Sourcepub fn is_invisible(&self) -> bool
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§
Auto Trait Implementations§
impl !Send for ParsedMethod
impl !Sync for ParsedMethod
impl Freeze for ParsedMethod
impl RefUnwindSafe for ParsedMethod
impl Unpin for ParsedMethod
impl UnsafeUnpin for ParsedMethod
impl UnwindSafe for ParsedMethod
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
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