Skip to main content

Module strategy

Module strategy 

Source
Expand description

Encoding strategies — the conventions for mapping Rust shapes onto WXF expressions. These sit a layer above the cursor (WxfReader/WxfWriter, which only know raw WXF tokens) and are shared by the #[derive] codegen and the hand-written std impls (Option, Result, …) so the wire format lives in exactly one place.

§Enum representation

A Rust enum is encoded as a List where the first element is the variant name (a string) and the remaining elements are the payload:

None            {"None"}
Some(v)         {"Some", v}
Rect(w, h)      {"Rect", w, h}

Constants§

DEFAULT_ENUM_HEAD
Default head for enum variants on the wire: {"VariantName", data...}.

Functions§

begin_data_variant
Begin a data-carrying variant: head["VariantName", data...]. The caller writes the n_data payload values immediately after.
read_data_header
No-op: the old strategy needed a separate "Data" key + List header; the new format inlines data directly after the variant name, so there is nothing extra to read. Kept for API compatibility with derived code.
read_enum_header
Read an enum list header (token already consumed): skips the head, reads the variant name string, and returns (total_arity, variant_name). The caller reads the remaining total_arity - 1 payload values.
write_unit_variant
Write a unit variant: head["VariantName"]. Use DEFAULT_ENUM_HEAD for the standard {"VariantName"} form.