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 JsonOptionsImmutable policy carried by each JSON writer invocation.
Field indent
pub indent: usizeSpaces per indentation level; zero selects compact output.
Field depth
pub depth: usizeThe current container depth.
Field depthLimit
pub depthLimit: usizeThe greatest permitted container depth.
Associated function JsonOptions.compact
pub fn compact() -> JsonOptionsSelects compact output with the scanner's nesting limit.
Associated function JsonOptions.indented
pub fn indented(width: usize) -> JsonOptionsSelects indentation width while retaining the default nesting limit.
Method JsonOptions.child
pub effect<'life0> fn child<'life0>(self: &'life0 silk/json_output.JsonOptions) -> JsonOptions ! JsonErrorReturns policy for one nested container or fails before its opening delimiter.
Implementation Copy for JsonOptions
impl Copy for JsonOptionsJsonOutput
pub struct JsonOutputLow-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 WriterWrites 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 WriterValidates 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 WriterWrites 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 WriterWrites 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 WriterWrites a colon followed by one optional space.