Skip to main content

MethodReturnBuilder

Struct MethodReturnBuilder 

Source
pub struct MethodReturnBuilder {
    call_expr: String,
    strategy: ReturnStrategy,
    class_name: Option<String>,
    return_class: Option<String>,
    explicit_wrap: Option<ReturnWrap>,
    nullable: bool,
    chain_var: Option<String>,
    invisible: bool,
    indent: usize,
    raise_default: String,
}
Expand description

Builder for generating R method body lines with appropriate return handling.

Produces lines of R code for a method body, combining the .Call() expression with the return strategy and the tagged-condition error guard. Each class system has specialized builder methods (build_r6_body, build_s3_body, etc.) that produce idiomatic R code for that system.

Fields§

§call_expr: String

The .Call() expression string (e.g., ".Call(C_Counter__inc, .call = sys.call(), self)").

§strategy: ReturnStrategy

How to handle the return value (direct, chaining, or Self wrapping).

§class_name: Option<String>

R class name, required when strategy is ReturnSelf to construct the class wrapper (e.g., "Counter" for Counter$new(.ptr = result)).

§return_class: Option<String>

Rust return type name, required when strategy is ReturnOtherClass or ReturnOtherClassList (the element type in the list case). The write-time resolver maps this Rust name to the registered target class and constructor syntax, or falls back to the bare value on miss.

§explicit_wrap: Option<ReturnWrap>

Explicit constructor selection, before automatic return-shape tails.

§nullable: bool

The method returns Option<..>, so .val is NULL for None (the C wrapper converts the whole Option, as a function’s does): the class wrap or receiver passes it through instead of constructing from it.

§chain_var: Option<String>

Variable name to return for ChainableMutation strategy (e.g., "self" for R6, "x" for S3). Defaults to "self" if not set.

§invisible: bool

Wrap the final expression in invisible(...) (#1213). Set from a return-type marker (Invisible<T>) or the invisible method option; nothing is invisible by default.

§indent: usize

Number of leading spaces for each generated line.

§raise_default: String

The raise helper’s fallback call (CallAttribution::raise_default): sys.call() unless set, environment() for an S3 method (#1851).

Implementations§

Source§

impl MethodReturnBuilder

Source

pub fn new(call_expr: String) -> Self

Create a new builder with the given .Call expression.

Source

pub fn with_raise_default(self, raise_default: &str) -> Self

Set the raise helper’s fallback call (see CallAttribution::raise_default).

Source

pub fn with_invisible(self, invisible: bool) -> Self

Wrap the method’s final expression in invisible(...) (marker or invisible option, see ParsedMethod::is_invisible).

Source

fn apply_visibility(&self, lines: Vec<String>) -> Vec<String>

Wrap the last generated line’s expression in invisible(...) when the builder is marked invisible. Every tail ends with the expression the wrapper returns, so this is the single place visibility is applied.

Source

fn apply_visibility_expr(&self, expr: String) -> String

Inline-expression counterpart of Self::apply_visibility.

Source

pub fn with_strategy(self, strategy: ReturnStrategy) -> Self

Set the return strategy.

Source

pub fn with_class_name(self, class_name: String) -> Self

Set the class name (for Self returns).

Source

pub fn with_return_class(self, return_class: String) -> Self

Set the return class name (for cross-class ExternalPtr returns).

Source

pub fn with_return_class_from_method( self, method: &ParsedMethod, self_rust_type: &str, ) -> Self

Attach the method’s cross-class return name when this builder uses ReturnStrategy::ReturnOtherClass or ReturnStrategy::ReturnOtherClassList.

self_rust_type is the enclosing impl block’s own Rust type name (type_ident.to_string()) — every class-system generator already has parsed_impl.type_ident in scope alongside class_name, so this threads it through rather than widening ParsedMethod to carry it (#1375). It’s consulted only for the Vec<Self> case (ParsedMethod::returns_self_list), where it stands in for the missing element name: the write-time resolver keys off the Rust type name (ClassNameEntry::rust_type), which is not necessarily the same string as this builder’s class_name field — #[miniextendr(class = "Override")] makes the R-facing class name and the Rust struct name diverge, and class_name here is the former.

Source

pub fn with_nullable(self, nullable: bool) -> Self

Mark .val as NULL for None (an Option return; see nullable). with_return_class_from_method sets it for inherent methods.

Source

pub fn with_explicit_wrap(self, wrap: ReturnWrap) -> Self

Select an explicit class constructor from a marker or wrap attribute.

Source

pub fn with_chain_var(self, var: String) -> Self

Set the variable name to return for chaining (default: “self”).

Source

pub fn with_indent(self, indent: usize) -> Self

Set indentation level (number of spaces).

Source

fn return_other_class_expr(&self) -> String

Source

fn null_passes(&self, expr: String) -> String

Pass a NULL .val (an Option method’s None) through the cross-class wrap expr: no constructor takes NULL, and lapply() would turn it into list().

Source

fn return_other_class_list_expr(&self) -> String

List-shaped sibling of return_other_class_expr (#1284).

The LIST_ infix keeps the marker family disjoint from the scalar .__MX_WRAP_RETURN_ prefix: the scalar resolver rewrites unrecognized markers of its own prefix to the bare expression, so a shared prefix would destroy list markers before the list resolver saw them.

Source

fn build_with_tails(&self, tails: ReturnTails<'_>) -> Vec<String>

Emit:

<indent>.val <- <call_expr>
<indent>if (inherits(.val, ...) ...) return(...)
<tail lines — .val is live>

All paths capture the .Call() result, dispatch on the tagged condition value if present, and then run the class-specific tail.

Source

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

Build R code lines for the method body.

Returns a vector of strings, one per line (without trailing newlines).

Source§

impl MethodReturnBuilder

Specialized builders for different class systems.

Source

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

Build R6-style return (chains via self; invisible(self) only when the method is marked invisible, #1213).

Source

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

Build S3-style return (uses structure() for Self returns).

Source

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

Build S7-style method body lines (creates new S7 object with .ptr).

Returns lines suitable for embedding inside an outer function(...) { ... } block — unlike build_s7_inline which wraps the body in its own { } and is intended for callers that emit function(...) <expr> directly (e.g., S7 convert definitions).

Source

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

Build S4-style method body lines (uses methods::new() to wrap Self returns).

Returns lines suitable for embedding inside an outer function(...) { ... } block, mirroring build_s7_body.

Source

pub fn build_s7_inline(&self) -> String

Build S7-style return (creates new S7 object with .ptr).

Returns a multi-line block expression that performs the condition check inline (suitable for S7 property definitions / convert methods that require a single expression).

Source

pub fn build_s4_inline(&self) -> String

Build S4-style return (uses methods::new()).

Returns a multi-line block expression that performs the condition check inline.

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