value_to_repr

Function value_to_repr 

Source
pub fn value_to_repr(v: &Value) -> Result<Value, NotStorable>
Expand description

A lossless encoding of a Value, for the log and for snapshots.

Value::to_json is the wire form: it drops the type name of a record and unwraps a newtype, because that is what a browser wants. The log needs the opposite — a record that can be read back as exactly the value that was written, because replay compares digests. Hence two encodings, and a test that says why.

§Why this returns a Result

It used to encode Html, Attr and Closure as unit on the grounds that “neither can appear in a log”. That grounds was an assumption, not a check: nothing stops a program declaring model State: cached: Html, and the encoding would then write unit into the durable path, silently, and replay would rebuild a different state. A system whose correctness argument is “replay is exact” cannot have a lossy branch in the function that makes the log.

Until placement can prove such a type never reaches durable (Phase 2’s effect rows), refusing at the boundary is the honest position: the append fails, the process aborts by the same rule as any other failed append (§18.5 item 6), and nothing unreadable is ever committed.