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: StringThe .Call() expression string (e.g., ".Call(C_Counter__inc, .call = sys.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)).
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: boolThe 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: boolWrap 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: usizeNumber of leading spaces for each generated line.
raise_default: StringThe raise helper’s fallback call (CallAttribution::raise_default):
sys.call() unless set, environment() for an S3 method (#1851).
Implementations§
Source§impl MethodReturnBuilder
impl MethodReturnBuilder
Sourcepub fn with_raise_default(self, raise_default: &str) -> Self
pub fn with_raise_default(self, raise_default: &str) -> Self
Set the raise helper’s fallback call (see
CallAttribution::raise_default).
Sourcepub fn with_invisible(self, invisible: bool) -> Self
pub fn with_invisible(self, invisible: bool) -> Self
Wrap the method’s final expression in invisible(...) (marker or
invisible option, see ParsedMethod::is_invisible).
Sourcefn apply_visibility(&self, lines: Vec<String>) -> Vec<String>
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.
Sourcefn apply_visibility_expr(&self, expr: String) -> String
fn apply_visibility_expr(&self, expr: String) -> String
Inline-expression counterpart of Self::apply_visibility.
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_return_class(self, return_class: String) -> Self
pub fn with_return_class(self, return_class: String) -> Self
Set the return class name (for cross-class ExternalPtr returns).
Sourcepub fn with_return_class_from_method(
self,
method: &ParsedMethod,
self_rust_type: &str,
) -> Self
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.
Sourcepub fn with_nullable(self, nullable: bool) -> Self
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.
Sourcepub fn with_explicit_wrap(self, wrap: ReturnWrap) -> Self
pub fn with_explicit_wrap(self, wrap: ReturnWrap) -> Self
Select an explicit class constructor from a marker or wrap attribute.
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).
fn return_other_class_expr(&self) -> String
Sourcefn null_passes(&self, expr: String) -> String
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().
Sourcefn return_other_class_list_expr(&self) -> String
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.
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 (chains via self; invisible(self) only when
the method is marked invisible, #1213).
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> 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: 192 bytes