Scalars v0.1.0
TomlParseInteger
pub func TomlParseInteger(text: char8[..]) -> int64 ! TomlScalarError
Reads an integer, in any of the four bases TOML writes.
A leading zero is refused for a decimal integer, because 010 is eight in one language and ten in another
and TOML declines to pick: it is not an integer at all. A sign is refused on a based integer for the same
reason — the grammar does not offer one, so accepting it would be inventing a dialect.
Malformed at the first character that cannot be part of the integer, TooLong past the length bound, and
OutOfRange at the start when the digits are a number int64 cannot hold. Every offset is into text as
written, underscores included.
Parameters
| Name | Type | Description |
|---|---|---|
text | char8[..] | the scalar's own bytes |
Returns: the integer, or why it could not be read and where
TomlParseFloat
pub func TomlParseFloat(text: char8[..]) -> float64 ! TomlScalarError
Reads a float, including the infinities and NaN that TOML can spell and JSON cannot.
A point needs a digit on either side of it, which is what refuses .7 and 7. — both of which some readers
accept and some do not, so a document containing one means different things in different places.
Malformed at the first character that cannot be part of the float, TooLong past the length bound, and
OutOfRange at the start when the digits are a number float64 cannot hold. Every offset is into text as
written, underscores included.
Parameters
| Name | Type | Description |
|---|---|---|
text | char8[..] | the scalar's own bytes |
Returns: the float, or why it could not be read and where
TomlDateTimeShape
pub enum TomlDateTimeShape: int32 {
Offset = 1,
Local = 2,
DateOnly = 3,
TimeOnly = 4
}
Which of the four date-time shapes a token turned out to be. There is no case for "not a date-time": text that is none of the four is a failure with a position, not a fifth shape a caller has to remember to check for before reading the fields beside it.
Cases
| Name | Value | Description |
|---|---|---|
Offset | 1 | A date and a time with an offset, which names a moment. |
Local | 2 | A date and a time with no offset, which names a wall clock reading. |
DateOnly | 3 | A date alone. |
TimeOnly | 4 | A time alone. |
TomlDateTime
pub struct TomlDateTime {
pub shape: TomlDateTimeShape;
pub date: Date;
pub time: TimeOfDay;
pub offset: UtcOffset;
}
A date-time as TOML writes it: which of the four shapes it is, and the parts that shape carries.
The parts that the shape does not carry are present and meaningless — a DateOnly has a time of midnight
because the fields have to hold something — so shape is what decides which of them to read. That is why the
shape travels with the value rather than being returned beside it.
Fields
| Name | Type | Description |
|---|---|---|
shape | TomlDateTimeShape | Which of the four forms the text was. |
date | Date | The date, for every shape but TimeOnly. |
time | TimeOfDay | The time, for every shape but DateOnly. |
offset | UtcOffset | The offset, for Offset alone. UTC otherwise, which means nothing there. |
TomlParseDateTime
pub func TomlParseDateTime(text: char8[..]) -> TomlDateTime ! TomlScalarError
Reads any of TOML's four date-time forms, reporting which one it was.
The four are genuinely different things and the difference matters: an offset date-time names a moment, and a
local date-time names a reading of a wall clock that different places reach at different moments. Collapsing
them by assuming UTC is how a meeting ends up an hour out, so nothing here supplies an offset that the text
did not.
Malformed at the byte where the text stops being one of the four forms — the separator that is not one, the
field the calendar rejects, or the end of the text when it stops early. The calendar's own refusals arrive
here too: the thirty-first of February is four correct digit pairs and not a date.
Parameters
| Name | Type | Description |
|---|---|---|
text | char8[..] | the scalar's own bytes |
Returns: the date-time and which shape it is, or why it could not be read and where