Skip to main content

ParsedMethod

Struct ParsedMethod 

Source
pub struct ParsedMethod {
    pub ident: Ident,
    pub env: ReceiverKind,
    pub sig: Signature,
    pub vis: Visibility,
    pub doc_tags: Vec<String>,
    pub method_attrs: MethodAttrs,
    pub param_defaults: HashMap<String, String>,
}
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§

§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.

§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(default = "...")]

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 ExternalPtr receiver (ExternalPtrRef, ExternalPtrRefMut, 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: ImplItemFn, _class_system: ClassSystem, ) -> Result<Self>

Parse a method from an impl item.

Regular doc comments are auto-converted to @description for all class systems.

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 is likely a finalizer. Inferred from: consumes self (by value) + doesn’t return Self.

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 as a string.

Source

pub fn c_wrapper_ident(&self, type_ident: &Ident, label: Option<&str>) -> Ident

C wrapper identifier for this method.

Format: C_{Type}__{method} or C_{Type}_{label}__{method} if labeled.

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_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

pub fn returns_unit(&self) -> bool

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

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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