packages

toml

On this page

TOML 1.1.0. parse reads a document into a Value table, to_str writes one, and ToToml / FromToml (with #[derive(Toml)]) map Nabi types to and from Value, as std's nabion does for NABION.

Decode errors carry a path (.servers[1].port); from_str turns it into line:col by re-reading the document up to that path, so the happy path keeps no positions.

Modules

  • datetime TOML date / time values (RFC 3339, with TOML's local forms).
  • read TOML 1.1.0 reader: a recursive descent over the bytes of the document that builds the table tree as it goes, with each table's origin kept by path so redefinitions are caught.
  • write TOML text of a table: plain keys first, then [table] sections and [[array]] elements, each table under its full dotted header.

Re-exports

datetime::{Date, Time, Datetime}Source

pub use datetime::{Date, Time, Datetime}
  • Date A calendar date.
  • Time A time of day.
  • Datetime One of TOML's four date-time forms, by which parts are present: offset date-time (all three), local date-time (date + time), local date (date), local time (time).

Structs

TomlErrorSource

pub struct TomlError

A read or decode error. line / col (1-based, code points) are 0 when the value did not come from text; path names the failing part (.servers[2].port, ."a b", empty at the root).

  • pub fn new(msg: str) -> TomlError§

    Source
  • pub fn within(self, seg: str) -> TomlError§

    Source

    self one level down: seg (.name, [3]) goes in front of the path.

  • pub fn message(self) -> str§

    Source

    What went wrong, without the position.

  • pub fn line(self) -> u32§

    Source

    1-based line, 0 when the value did not come from text.

  • pub fn col(self) -> u32§

    Source

    1-based column in code points, 0 when the value did not come from text.

  • pub fn path(self) -> str§

    Source

    The failing part (.servers[2].port), empty at the root.

Trait implementations 3
  • impl Display for TomlError
  • impl Debug for TomlError
  • impl Error for TomlError

OptionsSource

pub struct Options

How documents are written.

  • pub version: Version = Version::V1_0§

    Source

    The forms the output may use. 1.1 adds \e / \xHH escapes, times without zero seconds and inline tables over several lines. Default: 1.0, which every TOML reader takes.

  • pub width: usize = 100§

    Source

    Columns an array or inline table may take before it is split over lines. Default: 100.

Enums

ValueSource

pub enum Value

A TOML value. A document is a Table; tables keep insertion order.

Trait implementations 1
  • impl Display for Value

VersionSource

pub enum Version

A TOML version. The names keep the version's dot as _.

Traits

ToTomlSource

pub trait ToToml

A Nabi value as TOML. none (from T | none) leaves the key out; TOML has no null.

FromTomlSource

pub trait FromToml

A Nabi value from TOML; the target type decides how v reads.

Functions

parseSource

pub fn parse(s: str, version: Version = Version::V1_1) throws (TomlError) -> Value

Read one document into a Value::Table. version 1.0 rejects the forms TOML 1.1 added.

to_strSource

pub fn to_str<T: ToToml>(x: T, opts: Options | none = none) -> str

x as a TOML document. Panics unless x is written as a table, or when a none sits in an array.

from_strSource

pub fn from_str<T: FromToml>(s: str) throws (TomlError) -> T

Read a document as a T; errors carry the line:col of the part that did not fit.

to_valueSource

pub fn to_value<T: ToToml>(x: T) -> Value

x as a Value. Panics on none: it has no TOML form outside a table, where to_str leaves the key out.

from_valueSource

pub fn from_value<T: FromToml>(v: Value) throws (TomlError) -> T

v as a T.