fn generate_field_syntax_helpers(
type_name: &str,
pub_slots: &[&SidecarSlot],
field_error: &FieldErrorOptions,
every_read: bool,
writes: 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).
Without writes there is no setter switch(): the read-only form’s
writers refuse every field, and its setter routines are not registered
(#2292).
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. The setter arm
of a field without an R setter (a Computed or #[r_data(read_only)]
one, #2268) calls .rdata_read_only_<Type>, which raises
miniextendr_read_only_field with the calling method’s frame
(parent.frame()) resolved the same way; the writers of r_data_accessors = "read_only" call it for every field. The liveness check returns the
same kind of value as the accessors, 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), and field_error(read_only_hint = "...") one
after the miniextendr_read_only_field message, each %s the field’s
name (#2268) (r_hint_parts).