Skip to main content

MethodReturnBuilder

Struct MethodReturnBuilder 

Source
pub struct MethodReturnBuilder {
    call_expr: String,
    strategy: ReturnStrategy,
    class_name: Option<String>,
    chain_var: Option<String>,
    indent: usize,
}
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 = match.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)).

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

§indent: usize

Number of leading spaces for each generated line.

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_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_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 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 (uses invisible(self) for chaining).

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