Silk

silk/toml_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.

TOML document and value output through the ambient Writer.

When to use

Use TomlOutput.write for an owned TOML document. Unsupported scalar spellings and container shapes fail before the first write. Writer failures may leave an accepted prefix.

Examples

Write a parsed document

import silk.allocator as Allocators {Allocator, OutOfMemoryError}
import silk.effect as Effects {Effect}
import silk.toml_output as Outputs {TomlOutput}
import silk.toml_scanner as Scanners {TomlError}
import silk.toml_value as Values {Toml}
import silk.usize as Sizes
import silk.writer as Writers {Writer, WriterError}

struct Count {
  bytes: usize
}

effect fn writeAll(self: &mut Count, data: &[u8]) -> () ! WriterError {
  self.bytes = self.bytes + data.length
}

effect fn flush(self: &mut Count) -> () ! WriterError {
  return ()
}

impl Writer for Count {
  writeAll: Count.writeAll
  flush: Count.flush
}

effect fn write() -> i32 ! TomlError | OutOfMemoryError | WriterError {
  let mut allocator = Allocator.systemAllocatorProvider()
  let document = run Toml.parse(b"name = \"Ada\"\n")
    |> Effect.provideMut<Allocator>(&mut allocator)
  let mut output = Count {bytes: Sizes.ZERO}
  run TomlOutput.write(&document)
    |> Effect.provideMut<Allocator>(&mut allocator)
    |> Effect.provideMut<Writer>(&mut output)
  if output.bytes > Sizes.ZERO {
    return 0
  }
  return 1
}

effect fn recover(error: TomlError | OutOfMemoryError | WriterError) -> i32 {
  return 2
}

pub fn main() -> i32 {
  return run Effect.catchAll(write(), recover)
}

Import as TomlOutput with import silk.toml_output { TomlOutput }.

Public declarations: 1.

TomlOutput

pub struct TomlOutput

Output operations for an owned document or a value inside an assignment.

Associated function TomlOutput.write

pub effect<'life0> fn write<'life0>(document: &'life0 silk/toml_value.Value) -> () ! TomlError | OutOfMemoryError | WriterError ? &mut Allocator | &mut Writer

Writes a complete document, preserving table and array-of-tables structure.

Details

Invalid scalar text or container structure fails before the first write. Writer failure can leave an accepted prefix. This operation does not flush the Writer.

Associated function TomlOutput.writeString

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

Writes a quoted TOML basic string.

Associated function TomlOutput.writeKey

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

Writes one decoded key with bare spelling when possible.

On this page