Skip to main content

rust_codec

Function rust_codec 

Source
pub fn rust_codec(
    ast: &Ast,
    type_: Id<TypeNode>,
    key: LayoutKey,
) -> Result<Vec<Item>, EncodeError>
Expand description

Build the encode and decode functions for one type, with the Default impl and — for a keyed type — the key-holder pair.

This column writes a member’s collection where the member is, in the parent’s own body and through a closure, and never hoists it into a routine named after its element type. So the bound-in-the-name defect the other columns carry — sequence<long> and sequence<long, 4> sharing one hoisted routine, the first declared deciding whether the check exists — cannot reach here: every bound travels as an argument at the member’s own call site (write_string_bounded, write_sequence_bounded, and the fit_… pair on the read side). Measured on @final struct S { sequence<long> b; sequence<long, 4> a; }; in both declaration orders: both members keep exactly the bound their declaration gives them. crates/lang-rules/src/emit/zig.rs’s bound_tag is the fix in the columns that do hoist.

§Errors

EncodeError when the layout cannot be planned or a member has no writer — never a body that leaves a member out.