fn generate_setter_body(struct_name: &Ident, slot: &SidecarSlot) -> TokenStreamExpand description
Generate the token stream for a sidecar setter function body.
Stores the incoming R SEXP value in the slot. The strategy depends on the
slot kind:
Sidecar: validatesvaluewithTryFromSexp::<T>(a failure raises the conversion error) and stores it in the external pointer’s protection list, which roots it; a live struct’s pending value for the field is dropped.- Scalar kinds: writes the struct field, using
Rf_as*or coercion for single-element extraction; an input that doesn’t reduce to a single non-NA scalar raises a conversion error instead of silently storing an NA/falsesentinel. Conversion: usesTryFromSexp::try_from_sexp; a failed conversion raises a conversion error instead of silently dropping the write.
Returns the external pointer x (for R’s invisible return convention).
The body runs inside with_r_unwind_protect (see the emission site in
generate_sidecar_accessors); a bad receiver panics with the main-path
expected ExternalPtr<T> message and conversion failures return a tagged
condition SEXP with kind conversion — both are re-raised by the R
wrapper. Sidecar accessors have no __miniextendr_call slot (#344/#348),
so the tagged conditions carry null call attribution.
A Computed slot has no setter: the result is empty, and the caller
emits none.