fn generate_field_syntax_helpers(
type_name: &str,
pub_slots: &[&SidecarSlot],
field_error: &[String],
no_field_hint: Option<&str>,
every_read: bool,
) -> StringExpand description
Generate the R helpers the $ / [[ field methods of r_data_accessors
share on S3, S4 and env classes (#1848): the field names, a getter and a
setter switch() over the fields’ .Call()s, the classed
miniextendr_no_field error naming the fields, the classes the methods
put in front of their own errors (field_error, NULL without them,
#1899), and the liveness check of restored(refuse = "every_read")
with the flag that gates it (FALSE and a stub without it, #1901).
Prepared for every type with R accessors, whatever #[externalptr(...)]
names, and bundled with its internal accessor rendering. The writer selects
that rendering only when an impl enables field syntax, so the impl’s option
never depends on the derive attribute. The
helpers are named by the Rust type (crate::naming::rdata_helper_name);
the field names and the switch() labels are the fields’ R names, in
declared order, computed fields included (#1891, #1883).
Every arm passes TRUE as the accessor’s require_live flag, so the
field methods refuse a pointer restored from a saved session (the
standalone accessors pass FALSE and keep reading its Sidecar values).
The accessors return a failed conversion or a panic as a tagged condition
value with no call; the calling method raises it with its own frame as
the fallback, so the condition reports x$keys <- value. A computed
field’s setter arm raises miniextendr_read_only_field itself, with the
calling method’s frame (parent.frame()) resolved the same way. The
liveness check returns the same kind of value, which the method raises.
field_error(no_field_hint = "...") adds a sentence after the field list
of the miniextendr_no_field message, each %s in it replaced by the
name asked for (#2112). The hint is split on %s here and pasted around
the name, so any other % or \ in it, or in the name, stays as written.