r8to_json() writes a value as a document: its type, the versions of the types it contains, and its fields. r8from_json() reads a document into a value of the type:
Error:
! Cannot read `demo::Resampler`: 1 problem
- `n_resamples` must be at least 2; found 1. [below_min]
A document is RFC 8785 text in declaration order, so a value has one document whichever language wrote it; the Rust crate rtemis-r8 writes and reads the same documents.
A document records the hash of what each declaration says about a value, in $declarations. After the declaration changes, a document that was written before is refused, since its fields may mean something else:
Error:
! Cannot read `demo::Dose`: 1 problem
- the document was written under another declaration of `demo::Dose` than the registered, and does not hold it; `r8to_json(x, declarations = TRUE)` writes one that does, and `r8from_json(declaration = "any")` reads it as one of the registered [declaration_changed]
With declarations = TRUE the document holds the declarations too, so that the error names what differs, and a document whose fields mean the same, as after a new optional field, is read:
r8from_json(Dose, full)
Error:
! Cannot read `demo::Dose`: 1 problem
- `amount` was in `mg`, and is in `mg/kg` [declaration_changed]
declaration = "any" reads a document as one of the registered declaration, on the caller’s responsibility. A document without $declarations, as one written by hand, claims none and is read:
A change to the type’s declaration, other than to its descriptions, changes the hash of its values, so a hash identifies a value and the declaration it was checked against.