pub enum ReturnStrategy {
ReturnSelf,
ReturnOtherClass,
ReturnOtherClassList,
ChainableMutation,
Direct,
}Expand description
Return handling strategy for class methods.
Determines how the R wrapper function processes and returns the .Call() result.
Each class system generator uses this to produce idiomatic R return code.
Variants§
ReturnSelf
The method returns Self. The wrapper wraps the raw pointer result with
the appropriate class attribute or creates a new class object (e.g.,
R6Class$new(.ptr = result) or structure(result, class = "...")).
ReturnOtherClass
The method returns a bare type name that may be another registered
ExternalPtr-backed class. The final decision is deferred to
write_r_wrappers_to_file, where the complete class registry is known.
ReturnOtherClassList
The method returns a list of values (Vec<Class>, plus its
Option<Vec<Class>> / Result<Vec<Class>, E> wrappers; an Option’s
NULL passes through the wrap) whose element type may be another registered
ExternalPtr-backed class (#1284). Deferred to write_r_wrappers_to_file
like ReturnOtherClass, but through a
distinct .__MX_WRAP_LIST_RETURN_* marker that resolves to a per-element
lapply(...) wrap. The marker prefix must never overlap the scalar
.__MX_WRAP_RETURN_ family: the scalar resolver rewrites unrecognized
markers of its own prefix to the bare expression, so a shared prefix
would consume list markers before the list resolver ran.
ChainableMutation
The method is a &mut self method returning (). The wrapper calls the
.Call() for its side effect and returns the receiver (self/x) for
method chaining. The receiver is returned visibly unless the method is
marked Invisible<..> / invisible (#1213).
Direct
Default strategy: return the .Call() result directly without wrapping.
Implementations§
Source§impl ReturnStrategy
impl ReturnStrategy
Sourcepub fn for_method(method: &ParsedMethod) -> Self
pub fn for_method(method: &ParsedMethod) -> Self
Determine the return strategy for a parsed method.
- Methods that return
Self,Result<Self, E>, orOption<Self>useReturnSelf. The C wrapper already raised onErr(seecrate::c_wrapper_builder::ReturnHandling::ResultExternalPtr) and givesNULLforNone(seecrate::c_wrapper_builder::ReturnHandling::OptionExternalPtr), which passes through; any other.valis a bare ExternalPtr — identical in shape to the bare-Selfcase — and gets the same class-wrapping tail. - In-place builders (
&mut self -> &mut Self/&self -> Self) and&mut self -> ()methods useChainableMutation. Both return the receiver object (x/self, visibly unless marked invisible) so the call composes under the native pipe (obj |> set_a(1) |> set_b(2)); the C wrapper hands back the same ExternalPtr handle (seecrate::c_wrapper_builder::ReturnHandling::SelfHandle).
A visibility marker on the return type (Invisible<Self>,
Invisible<()>, …) is peeled at parse time
(ParsedMethod::sig holds the inner type), so it never changes the
strategy; it only sets MethodReturnBuilder::with_invisible.
- Bare capitalized return types that are not known primitives/containers
use
ReturnOtherClass; write-time registry lookup wraps registered classes and leaves false positives unchanged. This also covers the explicit-handle spellingExternalPtr<Class>(#1375) — the detector peels through it to the same wrapped name. Vec<Class>(and itsOption/Resultwrappers; anOptionreturn’sNULLpasses through) useReturnOtherClassList; write-time registry lookup wraps registered element classes vialapplyand leaves false positives unchanged (#1284). This also coversVec<ExternalPtr<Class>>andVec<Self>(#1375) — the latter viareturns_self_list(), since the scalar detector can’t nameSelf;with_return_class_from_methodsubstitutes the actual name.- All other methods use
Direct.
Trait Implementations§
Source§impl Clone for ReturnStrategy
impl Clone for ReturnStrategy
impl Copy for ReturnStrategy
Source§impl Debug for ReturnStrategy
impl Debug for ReturnStrategy
Source§impl Eq for ReturnStrategy
impl Eq for ReturnStrategy
1.0.0 (const: unstable) · Source§#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
implementation detail of #[derive(Eq)]
Source§#[doc(hidden)]fn assert_fields_are_eq(&self)
#[doc(hidden)]fn assert_fields_are_eq(&self)
derive_eq_internals)Source§impl PartialEq for ReturnStrategy
impl PartialEq for ReturnStrategy
impl StructuralPartialEq for ReturnStrategy
impl TrivialClone for ReturnStrategy
Auto Trait Implementations§
impl Freeze for ReturnStrategy
impl RefUnwindSafe for ReturnStrategy
impl Send for ReturnStrategy
impl Sync for ReturnStrategy
impl Unpin for ReturnStrategy
impl UnsafeUnpin for ReturnStrategy
impl UnwindSafe for ReturnStrategy
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Printable for 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: 1 byte
Size for each variant:
ReturnSelf: 0 bytesReturnOtherClass: 0 bytesReturnOtherClassList: 0 bytesChainableMutation: 0 bytesDirect: 0 bytes