pub fn lower_field_default_wire(
init: &Expr,
expected: &TypeRef,
types: &HashMap<String, Arc<TypeDecl>>,
) -> Result<String, String>Expand description
Events slice 3a (#972): the wire-form JSON literal an event field’s
default deserialises from when its key is absent from the incoming JSON.
Type-directed — given the field’s expected TypeRef and the visible
types table, every syntactic ambiguity (a bare Ident that is really a
sum variant, a FieldAccess that is a qualified nullary variant) resolves
the same way the checker resolves it, just narrower (a bare name must
match a variant of this expected sum specifically) — so this needs no
per-expression Ty map (expr_types), which a subscriber regenerating a
publisher’s own event codec (emit_consumed_context_helpers) has no way
to obtain anyway (no cross-unit expr_types store exists).
Produces the value in its wire shape (kind discriminant for a sum,
matching emit_sum_codec’s generated Option/Result instantiations
exactly — never the in-memory tag discriminant, and never a qualified
reference like Region.Domestic into a value namespace the emitting
module may not import), so it can be spliced in as the field’s raw JSON
access and re-enter emit_field_deserialise (bynk-emit) completely
unchanged.
Err(reason) for anything not closed-form. The caller
(bynk-emit/src/project/validate.rs’s event-field-default check) turns
that into bynk.event.bad_field_default at check time, so a value this
function cannot build should never reach emit_record in practice — the
.ok() fallback there is a non-panicking safety net, not the intended
rejection path.