silk/json_reflect
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Explicit JSON serialization of visible named aggregate fields.
When to use
Use JsonReflect.write for a struct whose visible fields each implement Serialize.
Call it directly or from the struct's hand-written Serialize witness.
Details
Fields are written in declaration order. Reflection uses this module's visibility, so private fields of a type declared elsewhere are omitted. The result is that type's visible projection, not necessarily its complete state. Writing requires no JSON-owned allocation.
Gotchas
Generic reflected deserialization is unavailable: public reflection can borrow fields but cannot construct an arbitrary aggregate from decoded owned fields.
Import as JsonReflect with import silk.json_reflect { JsonReflect }.
Public declarations: 1.
JsonReflect
pub struct JsonReflectOperations for writing the visible projection of a named aggregate.
Associated function JsonReflect.write
pub effect<'life1 & 'life2> fn write<T: 'life1 & 'life2, 'life1, 'life2>(value: &'life1 T, options: &'life2 silk/json_output.JsonOptions) -> () ! JsonError | WriterError ? &mut WriterWrites one JSON object from visible labeled fields in declaration order.
Details
Every visible field must implement Serialize. Unsupported aggregate kinds and missing
field witnesses fail during specialization. A Writer failure can leave a partial object.