Skip to main content

generate_setter_body

Function generate_setter_body 

Source
fn generate_setter_body(
    struct_name: &Ident,
    slot: &SidecarSlot,
    _prot_index_lit: &LitInt,
) -> TokenStream
Expand description

Generate the token stream for a sidecar setter function body.

Converts the incoming R SEXP value and writes it to the corresponding Rust struct field. The conversion strategy depends on the slot kind:

  • RawSexp: stores the SEXP directly.
  • Scalar kinds: uses Rf_as* or coercion for single-element extraction.
  • Conversion: uses TryFromSexp::try_from_sexp, silently ignoring errors.

Always returns the external pointer x (for R’s invisible return convention). No-op if the external pointer address is null.