pub enum ReturnHandling {
Show 20 variants
Unit,
RawSexp,
ExternalPtr,
SelfHandle,
SelfHandleResult,
SelfHandleOption,
IntoR,
OptionUnit,
OptionSexp,
OptionIntoR,
OptionClassPayload,
OptionExternalPtr,
ResultUnit,
ResultSexp,
ResultIntoR,
ResultNullOnErr,
ResultExternalPtr,
AsListOf,
AsExternalPtrOf,
AsNativeOf,
}Expand description
Strategy for converting a Rust return value into an R SEXP.
Determined automatically by detect_return_handling from the function’s return type,
or set explicitly via CWrapperContextBuilder::return_handling. Each variant
handles a different return type pattern, controlling how the C wrapper converts
the Rust value back to R and how errors/None values are surfaced.
Variants§
Unit
Returns unit type () – emits R_NilValue.
RawSexp
Returns raw SEXP – passes the value through unchanged (no conversion).
ExternalPtr
Returns Self – wraps the value in an ExternalPtr via ExternalPtr::new.
SelfHandle
Returns &Self / &mut Self (an in-place builder) – evaluates the call
for its side effect (the mutation already happened through &mut self),
discards the returned borrow, and returns the same self_sexp handle
unchanged. This gives R in-place value semantics with no clone: the R
object the user piped in is returned verbatim, wrapping the now-mutated
Rust value. Only valid for instance methods (requires self_sexp).
SelfHandleResult
Fallible in-place step whose call expression yields Result<(), E>
(&mut self -> Result<&mut Self, E>, or self -> Result<Self, E> after
the write-back closure): raise on Err, return the same self_sexp
handle on Ok (#1432, #1433).
SelfHandleOption
Option sibling of SelfHandleResult: the
call yields Option<()>; NULL on None, as every Option return
gives, and the same handle on Some.
IntoR
Returns an arbitrary type T: IntoR – converts via IntoR::into_sexp.
OptionUnit
Returns Option<()> – raises an error on None, otherwise emits R_NilValue.
OptionSexp
Returns Option<SEXP> – raises an error on None, otherwise passes through.
OptionIntoR
Returns Option<T> – calls IntoR::into_sexp on the whole Option, so None
becomes whatever IntoR for Option<T> gives: NULL for containers, references
and pointers, a typed NA for scalars. This is the one rule for an Option<T>
return from a standalone function, an inherent method and a trait method
(#1415, #2088); detect_return_handling picks it for every Option<T> but
the shapes below.
OptionClassPayload
Returns Option<T> under an explicit class wrap (Option<WrapAs*<T>> or
wrap = "..."): Some converts the class payload through T: IntoR, None
is NULL, as IntoR for Option<T> would give if it could exist (the orphan
rule refuses it in the class’s crate). The R wrapper’s class constructor lets
NULL through.
OptionExternalPtr
Returns Option<Self> – a lookup-shaped fallible constructor (e.g. try_find).
A method-only shape: Some(Self) is wrapped in an ExternalPtr via
ExternalPtr::new (same as ExternalPtr), since Self
generally has no IntoR, and the Option<ExternalPtr<Self>> converts as
any Option does: None is NULL. The R-side wrapper treats a non-NULL
value exactly like a bare Self return (wrapped class object via
ReturnStrategy::for_method — see ParsedMethod::returns_option_self).
ResultUnit
Returns Result<(), E> – raises an error on Err, otherwise emits R_NilValue.
ResultSexp
Returns Result<SEXP, E> – raises an error on Err, otherwise passes through.
ResultIntoR
Returns Result<T, E> – raises an error on Err, otherwise converts via IntoR::into_sexp.
ResultNullOnErr
Returns Result<T, ()> – maps Err(()) to Err(NullOnErr) then converts via IntoR.
None/Err maps to R NULL (unit error is a deliberate sentinel, not a Rust failure).
ResultExternalPtr
Returns Result<Self, E> – a fallible constructor-shaped method (e.g. from_r,
try_new). Raises an error on Err (same as ResultIntoR), but
wraps Ok(Self) in an ExternalPtr via ExternalPtr::new (same as
ExternalPtr) instead of routing it through IntoR (which Self
generally does not implement). The R-side wrapper mirrors this: a successful return is
treated exactly like a bare Self return (wrapped class object via
ReturnStrategy::for_method — see ParsedMethod::returns_result_self).
AsListOf
Returns T where T: IntoList – wraps in AsList(result) then calls IntoR::into_sexp.
Produced when #[miniextendr(prefer = "list")] is used on a function returning T: IntoList.
Distinct from returning AsList<T> explicitly only in that the wrapping is generated
by the macro rather than written by the user.
AsExternalPtrOf
Returns T where T: IntoExternalPtr – wraps in AsExternalPtr(result) then calls IntoR::into_sexp.
Produced when #[miniextendr(prefer = "externalptr")] is used on a function returning
T: IntoExternalPtr. Distinct from the existing ExternalPtr variant (which boxes Self
via ExternalPtr::new): this variant calls IntoExternalPtr::into_external_ptr() on T.
AsNativeOf
Returns T where T: RNativeType – wraps in AsRNative(result) then calls IntoR::into_sexp.
Produced when #[miniextendr(prefer = "native")] is used on a function returning T: RNativeType.
Trait Implementations§
Source§impl Clone for ReturnHandling
impl Clone for ReturnHandling
Auto Trait Implementations§
impl Freeze for ReturnHandling
impl RefUnwindSafe for ReturnHandling
impl Send for ReturnHandling
impl Sync for ReturnHandling
impl Unpin for ReturnHandling
impl UnsafeUnpin for ReturnHandling
impl UnwindSafe for ReturnHandling
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,
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:
Unit: 0 bytesRawSexp: 0 bytesExternalPtr: 0 bytesSelfHandle: 0 bytesSelfHandleResult: 0 bytesSelfHandleOption: 0 bytesIntoR: 0 bytesOptionUnit: 0 bytesOptionSexp: 0 bytesOptionIntoR: 0 bytesOptionClassPayload: 0 bytesOptionExternalPtr: 0 bytesResultUnit: 0 bytesResultSexp: 0 bytesResultIntoR: 0 bytesResultNullOnErr: 0 bytesResultExternalPtr: 0 bytesAsListOf: 0 bytesAsExternalPtrOf: 0 bytesAsNativeOf: 0 bytes