Skip to main content

ReturnHandling

Enum ReturnHandling 

Source
pub enum ReturnHandling {
Show 18 variants Unit, RawSexp, ExternalPtr, SelfHandle, IntoR, OptionUnit, OptionSexp, OptionIntoR, OptionIntoRUnwrap, 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).

§

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> where Option<T>: IntoR – calls IntoR::into_sexp on the whole Option value. Suitable when the type has a direct impl IntoR for Option<T> (e.g., Option<&T>, Option<Vec<T>>, Option<i32>). None maps to whatever the IntoR impl returns (typically NULL or NA).

Use this variant explicitly via CWrapperContextBuilder::return_handling when the type has a direct IntoR impl for the whole Option. The auto-detector detect_return_handling conservatively returns OptionIntoRUnwrap instead since it cannot resolve trait impls at macro expansion time.

§

OptionIntoRUnwrap

Returns Option<T> where T: IntoR – unwraps the option first, then converts the inner value via IntoR::into_sexp. Raises an error on None. Suitable when T: IntoR but Option<T> doesn’t have a direct IntoR impl (e.g., Option<SomeExternalPtr>).

§

OptionExternalPtr

Returns Option<Self> – a lookup-shaped fallible constructor (e.g. try_find). Raises an error on None (same as OptionIntoRUnwrap), but wraps Some(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_option_self). Symmetric with ResultExternalPtr.

§

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

Source§

fn clone(&self) -> ReturnHandling

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReturnHandling

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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: 1 byte

Size for each variant:

  • Unit: 0 bytes
  • RawSexp: 0 bytes
  • ExternalPtr: 0 bytes
  • SelfHandle: 0 bytes
  • IntoR: 0 bytes
  • OptionUnit: 0 bytes
  • OptionSexp: 0 bytes
  • OptionIntoR: 0 bytes
  • OptionIntoRUnwrap: 0 bytes
  • OptionExternalPtr: 0 bytes
  • ResultUnit: 0 bytes
  • ResultSexp: 0 bytes
  • ResultIntoR: 0 bytes
  • ResultNullOnErr: 0 bytes
  • ResultExternalPtr: 0 bytes
  • AsListOf: 0 bytes
  • AsExternalPtrOf: 0 bytes
  • AsNativeOf: 0 bytes