std/toml/value

std/toml/src/value.trb

The tree of a TOML document, TomlValue, and the four date and time values TOML has: a date, a time, a date and time without an offset and a date and time with one. They are small value types of this package, each one written and read as its RFC 3339 text.

type TomlValue

type TomlValue with Show, Equals

One value of a TOML document, as a tree. A table keeps its keys in the order of the document.

The tree does not keep comments, the way a document was split into tables or whether a string was written in quotes of one kind or the other: it holds what the document says.

Examples

use Toml from "std/toml"

const tree = Toml().parse("name = \"web\"\nport = 8080\n")?
print tree.at("port")

case String

case String(value: String)

A string, with its escapes resolved.

case Integer

case Integer(value: Int)

An integer of 64 bits and a sign.

case Float

case Float(value: Float64)

A float, which may be inf, -inf or nan.

case Boolean

case Boolean(value: Bool)

true or false.

case OffsetDateTime

case OffsetDateTime(value: TomlOffsetDateTime)

A date and time with an offset from UTC.

case LocalDateTime

case LocalDateTime(value: TomlLocalDateTime)

A date and time without an offset.

case LocalDate

case LocalDate(value: TomlDate)

A date without a time.

case LocalTime

case LocalTime(value: TomlTime)

A time of day without a date.

case Array

case Array(items: List<Self>)

An array: its items in the order of the document, which may be of different kinds.

case Table

case Table(entries: List<TomlEntry>)

The entries of a table in the order the document wrote them.

fn at

fn at(key: String): Self?

The value of key when this is a table that has it.

fn items

fn items(): List<Self>

The items when this is an array, and an empty list for every other value.

fn entries

fn entries(): List<TomlEntry>

The entries when this is a table, and an empty list for every other value.

fn isTable

fn isTable(): Bool

true for a table.

fn updated

fn updated(key: String, value: Self): Self

The table with value set under key: replaced in place where the key is there, appended where it is not.

fn equals

fn equals(other: Self): Bool

Whether both are the same value. The keys of a table have no order in TOML, so tables are equal where they hold the same keys with equal values whatever order the document wrote them in, and nan equals nan: it is one value.

fn show

fn show(): String

The value as the text of a document would show it: a string in quotes, a table in braces.

type TomlEntry

type TomlEntry with Show, Equals

One key of a table and its value.

field key

key: String

The key as plain text, without the quotes it may have been written in.

field value

value: TomlValue

The value the key holds.

fn show

fn show(): String

key = value, with the key in quotes where it is not a bare name.

type TomlDate

type TomlDate with Show, Equals, Compare

A calendar date: 1979-05-27.

field year

year: Int

The year in the Gregorian calendar, four digits in the text.

field month

month: Int

The month, 1 to 12.

field day

day: Int

The day of the month, from 1 to the length of the month.

fn parse

static fn parse(text: String): Result<Self, DecodeError>

Reads 1979-05-27, with a four digit year and a day that exists in that month.

fn daysSinceEpoch

fn daysSinceEpoch(): Int

The number of days from 1970-01-01 to this day, negative before it.

fn compare

fn compare(other: Self): Ordering

Orders by the days since 1970-01-01, so an earlier day is the lesser one.

fn show

fn show(): String

The date as 1979-05-27, with the year to four digits and the month and day to two.

type TomlTime

type TomlTime with Show, Equals, Compare

A time of day without a date or an offset: 07:32:00 or 00:32:00.999999.

field hour

hour: Int

The hour, 0 to 23.

field minute

minute: Int

The minute, 0 to 59.

field second

second: Int = 0

The second, 0 to 60 where 60 is the leap second; 0 when the text has none.

field nanosecond

nanosecond: Int = 0

The fraction of the second, in nanoseconds: .5 is 500000000.

fn parse

static fn parse(text: String): Result<Self, DecodeError>

Reads 07:32:00, 07:32 and 07:32:00.999: the seconds are optional, as in TOML 1.1.

fn nanosecondsOfDay

fn nanosecondsOfDay(): Int

The nanoseconds from midnight.

fn compare

fn compare(other: Self): Ordering

Orders by the nanoseconds from midnight.

fn show

fn show(): String

07:32:00, with the fraction of the second after it where there is one.

type TomlLocalDateTime

type TomlLocalDateTime with Show, Equals, Compare

A date and a time without an offset: 1979-05-27T07:32:00.

field date

date: TomlDate

The day.

field time

time: TomlTime

The time of that day.

fn parse

static fn parse(text: String): Result<Self, DecodeError>

Reads 1979-05-27T07:32:00; the T may be a lower case t or a space.

fn compare

fn compare(other: Self): Ordering

Orders by date, and by time where the dates are the same.

fn show

fn show(): String

The date, a T and the time: 1979-05-27T07:32:00.

type TomlOffsetDateTime

type TomlOffsetDateTime with Show, Equals

A date and a time with an offset from UTC: 1979-05-27T07:32:00Z or 1979-05-27T00:32:00-07:00.

field dateTime

dateTime: TomlLocalDateTime

The date and time on the wall clock of the offset.

field offsetMinutes

offsetMinutes: Int = 0

The offset from UTC in minutes: Z is 0 and -07:00 is -420.

fn parse

static fn parse(text: String): Result<Self, DecodeError>

Reads 1979-05-27T07:32:00Z and 1979-05-27 00:32:00.5-07:00.

fn toTimestamp

fn toTimestamp(): Timestamp?

The nanoseconds from 1970-01-01 00:00:00 UTC to this point in time, as a Timestamp.

fn show

fn show(): String

1979-05-27T07:32:00Z, or the offset as +05:30 where it is not zero.

extend TomlDate with Encode, Decode

extend TomlDate with Encode, Decode

A date, a time and a date and time are written as their text and announced as a record of the type that holds nothing but that text - a wrapper - so that Toml can write them as TOML's own date and time values, and every other format writes the text.

fn encode

fn encode<Target: Encoder>(var target: Target)

fn decode

static fn decode<Source: Decoder>(var source: Source): Result<Self, DecodeError>

extend TomlTime with Encode, Decode

extend TomlTime with Encode, Decode

A time is written as its text, in the same wrapper as TomlDate, so that Toml writes it as a TOML local time.

fn encode

fn encode<Target: Encoder>(var target: Target)

fn decode

static fn decode<Source: Decoder>(var source: Source): Result<Self, DecodeError>

extend TomlLocalDateTime with Encode, Decode

extend TomlLocalDateTime with Encode, Decode

A date and time without an offset is written as its text, in the same wrapper as TomlDate.

fn encode

fn encode<Target: Encoder>(var target: Target)

fn decode

static fn decode<Source: Decoder>(var source: Source): Result<Self, DecodeError>

extend TomlOffsetDateTime with Encode, Decode

extend TomlOffsetDateTime with Encode, Decode

A date and time with an offset is written as its text, in the same wrapper as TomlDate.

fn encode

fn encode<Target: Encoder>(var target: Target)

fn decode

static fn decode<Source: Decoder>(var source: Source): Result<Self, DecodeError>