fn generate_getter_body(struct_name: &Ident, slot: &SidecarSlot) -> TokenStreamExpand description
Generate the token stream for a sidecar getter function body.
Reads the slot and returns it as an R SEXP. The strategy depends on the slot kind:
Sidecar: returns the value from the external pointer’s protection list, after flushing a live struct’s pending value for the field. It needs no live address, so withoutrequire_liveit also reads a pointer thatreadRDSbrought back; with it (the field methods ofr_data_accessors, #1891) a restored pointer is refused.- Scalar kinds: reads the struct field (accessed via the external pointer
address) and wraps it with
Rf_Scalar*. Conversion: clones the struct field and converts it withIntoR; under#[r_data(null_if_none)]theOption<T>converts as aNullable<T>, soNonereadsNULL(#2270). Under#[r_data(cache)]the converted value is kept and returned by the reads that follow until the value is borrowed exclusively (externalptr::sidecar_r_cached, #2271).Computed: calls thegetfunction on the live struct and converts its value withIntoR; aResultis an error boundary (#2269).
A failed IntoR conversion raises the classed result_err condition
(c_wrapper_builder::return_conversion, #2272).
The body runs inside with_r_unwind_protect (see the emission site in
generate_sidecar_accessors). The receiver is the pointer or an object
carrying it in .ptr, as for an instance method; an argument carrying no
pointer, a null pointer address, or a wrong stored type panics with the
same expected ExternalPtr<T> message the main class-method path uses.
The panic is transported as a tagged condition and re-raised by the R
wrapper.