TomlValue structv0.1.0

Source
A TOML value: one of the ten kinds, owning whatever it holds.
pub struct TomlValue {
    pub kind: TomlKind;
    pub integer: int64;
    // private fields
}

Move-only, because it owns strings and nested values. The allocator it was built with travels with it, so a subtree can be released without the caller having to remember where it came from.

Fields

NameTypeDescription
kindTomlKindWhich of the ten kinds this is.
integerint64The payload of an Integer.

Associated functions

Table

pub func Table(allocator: Allocator) -> TomlValue

An empty table, which is also the shape every other kind is built from: TOML has no null to start from.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: an empty table

Source

Array

pub func Array(allocator: Allocator) -> TomlValue

An empty array.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: an empty array

Source

Text

pub func Text(
    allocator: Allocator,
    value: char8[..]
) -> TomlValue ! TextError

A string value, whose bytes are copied and validated as UTF-8.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
valuechar8[..]the value to act on

Returns: that text as a string value, or an empty table when the allocator refused

Source

FromString

pub func FromString(
    allocator: Allocator,
    value: String
) -> TomlValue

A string value copying an already-built string.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
valueStringthe value to act on

Returns: that owned string as a string value

Source

Integer

pub func Integer(
    allocator: Allocator,
    value: int64
) -> TomlValue

An integer value.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
valueint64the value to act on

Returns: that integer as a value

Source

Float

pub func Float(
    allocator: Allocator,
    value: float64
) -> TomlValue

A float value, which TOML — unlike JSON — allows to be an infinity or a NaN.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
valuefloat64the value to act on

Returns: that float as a value

Source

Boolean

pub func Boolean(
    allocator: Allocator,
    value: bool
) -> TomlValue

A boolean value.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
valueboolthe value to act on

Returns: that boolean as a value

Source

OffsetDateTime

pub func OffsetDateTime(
    allocator: Allocator,
    date: Date,
    time: TimeOfDay,
    offset: UtcOffset
) -> TomlValue

A date and time with a known offset, which names a moment on the timeline.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
dateDatethe calendar date
timeTimeOfDaythe time of day
offsetUtcOffsetthe offset from UTC

Returns: a value carrying the date, the time and the offset from UTC

Source

LocalDateTime

pub func LocalDateTime(
    allocator: Allocator,
    date: Date,
    time: TimeOfDay
) -> TomlValue

A date and time with no offset, which names a wall clock reading rather than a moment.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
dateDatethe calendar date
timeTimeOfDaythe time of day

Returns: a value carrying the date and the time, with no offset

Source

LocalDate

pub func LocalDate(
    allocator: Allocator,
    date: Date
) -> TomlValue

A date with no time.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
dateDatethe calendar date

Returns: a value carrying the date alone

Source

LocalTime

pub func LocalTime(
    allocator: Allocator,
    time: TimeOfDay
) -> TomlValue

A time with no date.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
timeTimeOfDaythe time of day

Returns: a value carrying the time alone

Source

Methods

Kind

pub func Kind(self: &TomlValue) -> TomlKind

Which kind this value is.

Returns: which of the TOML kinds this is

Source

AsBoolean

pub func AsBoolean(
    self: &TomlValue,
    result: *var bool
) -> bool

The boolean payload, or false when this is not a boolean — which Kind distinguishes from a genuine false.

NameTypeDescription
result*var boolreceives the value when this reports true

Returns: whether this is a boolean

Source

AsInteger

pub func AsInteger(
    self: &TomlValue,
    result: *var int64
) -> bool

The integer payload, or false when this is not an integer. A float is not converted, even when its value happens to be whole: TOML distinguishes 1 from 1.0 and collapsing them here would throw away a distinction the document was making.

NameTypeDescription
result*var int64receives the value when this reports true

Returns: whether this is an integer

Source

AsFloat

pub func AsFloat(
    self: &TomlValue,
    result: *var float64
) -> bool

The float payload, or false when this is not a float.

NameTypeDescription
result*var float64receives the value when this reports true

Returns: whether this is a float

Source

AsText

pub func AsText(self: &TomlValue) -> StringView

The string payload, or an empty view when this is not a string.

Returns: the string, or an empty view when this is not one

Source

AsDate

pub func AsDate(self: &TomlValue, result: *var Date) -> bool

The date part, or false when this kind has none.

NameTypeDescription
result*var Datereceives the value when this reports true

Returns: whether this carries a date

Source

AsTime

pub func AsTime(
    self: &TomlValue,
    result: *var TimeOfDay
) -> bool

The time part, or false when this kind has none.

NameTypeDescription
result*var TimeOfDayreceives the value when this reports true

Returns: whether this carries a time

Source

AsOffset

pub func AsOffset(
    self: &TomlValue,
    result: *var UtcOffset
) -> bool

The offset, or false when this is not an offset date-time. A local date-time deliberately has none: it names a wall clock reading, and inventing an offset for it is how a meeting ends up an hour out.

NameTypeDescription
result*var UtcOffsetreceives the value when this reports true

Returns: whether this carries an offset from UTC

Source

Length

pub func Length(self: &TomlValue) -> uint

How many elements an array holds, or entries a table holds; zero for anything else.

Returns: how many elements or entries this holds; zero for anything else

Source

Push

pub func Push(
    self: &var TomlValue,
    value: TomlValue
) -> bool

Appends value to an array, taking ownership of it. Reports false when this is not an array or the allocator refused; value is consumed either way, so a caller does not have to decide who owns it on failure.

NameTypeDescription
valueTomlValuethe value to act on

Returns: whether the element was appended

Source

Insert

pub func Insert(
    self: &var TomlValue,
    key: String,
    value: TomlValue
) -> bool

Appends an entry to a table, copying the key and taking ownership of the value. The order entries are added in is the order they are kept and written, which is what makes a document round-trip recognisably. Nothing here rejects a repeated key — that is the parser's business, where the three different ways of repeating one can be told apart.

NameTypeDescription
keyStringthe key to look up
valueTomlValuethe value to act on

Returns: whether the entry was added

Source

At

pub func At(self: &TomlValue, index: uint) -> *TomlValue

The element at index, borrowed, or null when there is none.

NameTypeDescription
indexuintwhich one, counting from zero

Returns: the element at index, or null when there is none

Source

AtMutable

pub func AtMutable(
    self: &var TomlValue,
    index: uint
) -> *var TomlValue

The element at index, borrowed for modification, or null when there is none. This is how an array of tables grows: the header that opens a new one appends, and the lines under it are written into the last element in place.

NameTypeDescription
indexuintwhich one, counting from zero

Returns: the element at index for writing, or null when there is none

Source

Find

pub func Find(
    self: &TomlValue,
    key: StringView
) -> *TomlValue

The value under key, borrowed, or null when the table has none.

NameTypeDescription
keyStringViewthe key to look up

Returns: the entry with that key, or null when there is none

Source

FindMutable

pub func FindMutable(
    self: &var TomlValue,
    key: StringView
) -> *var TomlValue

The value under key, borrowed for modification, or null when the table has none.

NameTypeDescription
keyStringViewthe key to look up

Returns: the entry with that key for writing, or null when there is none

Source

EntryAt

pub func EntryAt(
    self: &TomlValue,
    index: uint
) -> *TomlEntry

The entry at index, borrowed, or null when there is none.

NameTypeDescription
indexuintwhich one, counting from zero

Returns: the entry at index, or null when there is none

Source

Destructor

func ~TomlValue(self: &var TomlValue)

Releases everything this value owns. Written out rather than left to the compiler, because a value owns its string and its children own theirs: the recursion here is the shape of the document, and stating it makes the ownership of a nested tree something a reader can check.

Source

TomlKind

pub enum TomlKind: int32 {
    Text = 0,
    Integer = 1,
    Float = 2,
    Boolean = 3,
    OffsetDateTime = 4,
    LocalDateTime = 5,
    LocalDate = 6,
    LocalTime = 7,
    Array = 8,
    Table = 9
}

Which kind of TOML value this is.

Source

Cases

NameValueDescription
Text0A string, whichever of the four forms it was written in.
Integer1A 64-bit signed integer.
Float2A 64-bit float, which unlike JSON may be an infinity or a NaN.
Boolean3true or false.
OffsetDateTime4A date and time with a known offset from UTC, which names a moment.
LocalDateTime5A date and time with no offset, which names a reading of a wall clock.
LocalDate6A date with no time.
LocalTime7A time with no date.
Array8An ordered sequence of values.
Table9A table of entries, in the order they were seen.

TomlEntry

pub struct TomlEntry {
    pub key: String;
    pub value: TomlValue;
}

One entry of a table: its key and its value.

Source

Fields

NameTypeDescription
keyStringThe key, already unquoted and unescaped.
valueTomlValueThe value.

Destructor

~TomlEntry

func ~TomlEntry(self: &var TomlEntry)

Releases the key and the value.

Source