Skip to main content

Module canonical

Module canonical 

Source
Expand description

Canonical bytes and digests (spec 002, 3.3).

Canonical bytes are written by this module’s own writer rather than by serde_json’s map order, so the form does not depend on whether any crate in the build enables serde_json/preserve_order: object keys are sorted by byte order, there is no insignificant whitespace, strings use serde_json escaping, and a fractional or exponent number is refused.

The record canonical form (spec 004, 5.6) differs only for numbers held as binary64, which write_binary64 writes itself rather than through serde_json’s formatter, whose digit choice at exact ties differs. It is for backend outputs, run records, judgments, reports and replay documents. A document without a binary64 number has the same bytes in both forms.

Enums§

CanonicalError
Why a value has no canonical form.

Functions§

canonical_bytes
The canonical bytes of any serializable value.
canonical_value_bytes
The canonical bytes of an already-built JSON value.
record_canonical_bytes
The record canonical bytes of a typed document (spec 004, 5.6); the form is defined for typed documents only, never for an untyped JSON value, whose numbers lose the binary64 distinction. Refused unless they parse back to an equal document whose record canonical bytes are the same bytes: a non-finite number, which serializes as null, never gets a form.
tagged_digest
sha256: and the lowercase hex SHA-256 of tag || 0x00 || bytes.
write_binary64
Write a finite binary64 (spec 004, 5.6): the shortest round-trip digits nearest the exact value, exact ties to the larger magnitude, as Rust’s core::fmt shortest mode gives them; plain notation for a decimal exponent e with -5 <= e < 16 and at least one fractional digit, otherwise d[.ddd]e+N or d[.ddd]e-N; zero as 0.0 or -0.0.