Silk

silk/json_object

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.

Effectful JSON object construction through the ambient Writer.

When to use

Use JsonObject to write named values with a Serialize implementation. Each operation keeps the object state in an Effect for the next operation.

Details

The object owns its comma and depth state. It does not own or borrow the Writer. A failed write can leave an accepted prefix in the Writer.

Import as JsonObject with import silk.json_object { JsonObject }.

Public declarations: 1.

JsonObject

pub struct JsonObject

Owned formatting state for one open JSON object.

Associated function JsonObject.begin

pub effect<'life0> fn begin<'life0>(options: &'life0 silk/json_output.JsonOptions) -> JsonObject ! JsonError | WriterError ? &mut Writer

Opens an object after checking its depth limit.

Associated function JsonObject.field

pub effect<'env> fn field<'env, T: 'env, E, ?R>(self: once Effect<'env; silk/json_object.JsonObject ! E ? R>, key: string<'env>, value: &'env T) -> JsonObject ! E | JsonError | WriterError ? R | &mut Writer

Writes one named value and returns the open object state.

Details

The incoming Effect runs once. If it fails, this operation writes nothing.

Associated function JsonObject.fieldIfSome

pub effect<'env> fn fieldIfSome<'env, T: 'env, E, ?R>(self: once Effect<'env; silk/json_object.JsonObject ! E ? R>, key: string<'env>, value: &'env silk/option.Option<T>) -> JsonObject ! E | JsonError | WriterError ? R | &mut Writer

Writes a present named value or leaves an absent member out of the object.

Details

The incoming Effect runs once. None does not write a key or a separator.

Associated function JsonObject.end

pub effect<'env> fn end<'env, E, ?R>(self: once Effect<'env; silk/json_object.JsonObject ! E ? R>) -> () ! E | JsonError | WriterError ? R | &mut Writer

Closes an object and returns the completed write.

Details

The incoming Effect runs once. If it fails, the closing brace is not written.

On this page