Silk

silk/json_output

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.

Allocation-free JSON string escaping and formatting through the ambient Writer.

When to use

Use JsonOutput when writing a JSON string, validated number, or container punctuation. JsonOptions chooses compact or indented output and bounds container depth.

Details

Each operation writes directly to Writer. A failed write may leave an accepted prefix; no operation flushes the provider or allocates JSON-owned storage.

Examples

Configure two-space indentation

import silk.json_output { JsonOptions }
import silk.usize

pub fn main() -> i32 {
  let options = JsonOptions.indented(2)
  return usize.toI32(options.indent)
}

Import as JsonOutput with import silk.json_output { JsonOutput }.

Public declarations: 2.

JsonOptions

pub struct JsonOptions

Immutable policy carried by each JSON writer invocation.

Field indent

pub indent: usize

Spaces per indentation level; zero selects compact output.

Field depth

pub depth: usize

The current container depth.

Field depthLimit

pub depthLimit: usize

The greatest permitted container depth.

Associated function JsonOptions.compact

pub fn compact() -> JsonOptions

Selects compact output with the scanner's nesting limit.

Associated function JsonOptions.indented

pub fn indented(width: usize) -> JsonOptions

Selects indentation width while retaining the default nesting limit.

Method JsonOptions.child

pub effect<'life0> fn child<'life0>(self: &'life0 silk/json_output.JsonOptions) -> JsonOptions ! JsonError

Returns policy for one nested container or fails before its opening delimiter.

Implementation Copy for JsonOptions

impl Copy for JsonOptions

JsonOutput

pub struct JsonOutput

Low-level JSON output operations shared by tree and typed serializers.

Associated function JsonOutput.writeString

pub effect<'life0> fn writeString<'life0>(value: string<'life0>) -> () ! WriterError ? &mut Writer

Writes one UTF-8 string with RFC 8259 quoting and control-byte escapes.

Associated function JsonOutput.writeNumber

pub effect<'life0> fn writeNumber<'life0>(value: string<'life0>) -> () ! JsonError | WriterError ? &mut Writer

Validates and writes one complete JSON number lexeme without reformatting it.

Associated function JsonOutput.separator

pub effect<'life0> fn separator<'life0>(options: &'life0 silk/json_output.JsonOptions, first: bool) -> () ! WriterError ? &mut Writer

Writes a comma before a later member or item and its optional indentation.

Associated function JsonOutput.line

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

Writes a newline and spaces for the current depth when indentation is enabled.

Associated function JsonOutput.colon

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

Writes a colon followed by one optional space.

On this page