std/toml/encoder

std/toml/src/encoder.trb

TomlEncoder: an Encoder that builds the TOML tree of a value, which the writer then writes. TOML has no null, so a field that holds nothing is left out of its table and an array cannot hold nothing; a document is a table, and so is the value it is written from.

type TomlEncoder

type TomlEncoder with Encoder

An Encoder that builds a TomlValue. A record is a table, and a record that announces no field is its one value.

field naming

naming: Naming = Naming.Unchanged

How the names of record fields are written as table keys.

fn result

fn result(): Result<TomlValue, TomlError>

What was written: a table, or the reason the value is no TOML.

fn nothing

var fn nothing()

None: in a field it leaves the field out, and TOML has no value to put anywhere else.

fn bool

var fn bool(value: Bool)

Writes a TOML boolean.

fn int

var fn int(value: Int64)

Writes a TOML integer.

fn unsigned

var fn unsigned(value: UInt64)

Writes a TOML integer; a value above the largest Int64 makes the result unwritable (64 bits and a sign).

fn float

var fn float(value: Float64)

Writes a TOML float; inf, -inf and nan are floats too.

fn decimal

var fn decimal(value: Decimal)

Writes the decimal as a TOML string of its text, since TOML has no decimal type.

fn string

var fn string(value: String)

Writes a TOML string.

fn bytes

var fn bytes(value: Bytes)

Bytes are a string of base64.

fn sequence

var fn sequence(length: Int?)

Opens an array; finish closes it into a TomlValue.Array. The length is not needed.

fn map

var fn map(length: Int?)

Opens a table of keys and values written in turn; finish closes it. The length is not needed.

fn record

var fn record(typeName: String)

Opens a record, which finish closes into a table, or into its one value where it announces no field.

fn variant

var fn variant(typeName: String, name: String)

Opens a case of a variant type, which finish closes into its name or into a table of one entry.

fn field

var fn field(name: String)

Names the next value of the open record or case, with the TomlEncoder.naming applied.

fn finish

var fn finish()

Closes the innermost open array, table, record or case and hands its value to the one around it.