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: StringThe .Call() expression string (e.g., ".Call(C_Counter__inc, .call = match.call(), self)").
strategy: ReturnStrategyHow 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: usizeNumber of leading spaces for each generated line.
Implementations§
Source§impl MethodReturnBuilder
impl MethodReturnBuilder
Sourcepub fn with_strategy(self, strategy: ReturnStrategy) -> Self
pub fn with_strategy(self, strategy: ReturnStrategy) -> Self
Set the return strategy.
Sourcepub fn with_class_name(self, class_name: String) -> Self
pub fn with_class_name(self, class_name: String) -> Self
Set the class name (for Self returns).
Sourcepub fn with_chain_var(self, var: String) -> Self
pub fn with_chain_var(self, var: String) -> Self
Set the variable name to return for chaining (default: “self”).
Sourcepub fn with_indent(self, indent: usize) -> Self
pub fn with_indent(self, indent: usize) -> Self
Set indentation level (number of spaces).
Sourcefn build_with_tails(&self, tails: ReturnTails<'_>) -> Vec<String>
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§impl MethodReturnBuilder
Specialized builders for different class systems.
impl MethodReturnBuilder
Specialized builders for different class systems.
Sourcepub fn build_r6_body(&self) -> Vec<String>
pub fn build_r6_body(&self) -> Vec<String>
Build R6-style return (uses invisible(self) for chaining).
Sourcepub fn build_s3_body(&self) -> Vec<String>
pub fn build_s3_body(&self) -> Vec<String>
Build S3-style return (uses structure() for Self returns).
Sourcepub fn build_s7_body(&self) -> Vec<String>
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).
Sourcepub fn build_s4_body(&self) -> Vec<String>
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.
Sourcepub fn build_s7_inline(&self) -> String
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).
Sourcepub fn build_s4_inline(&self) -> String
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§
impl Freeze for MethodReturnBuilder
impl RefUnwindSafe for MethodReturnBuilder
impl Send for MethodReturnBuilder
impl Sync for MethodReturnBuilder
impl Unpin for MethodReturnBuilder
impl UnsafeUnpin for MethodReturnBuilder
impl UnwindSafe for MethodReturnBuilder
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> 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: 88 bytes