toml::sift

The toml::sift module provides helper utilities for processing and validating toml:: structures, and for printing useful error messages when an incorrect configuration is encountered.

get can be used to easily locate a value in a TOML document. The get* functions like geti do the same but additionally validate the type of the value. try* functions do the same but let you pass a default value for if none exists.

The get* functions return an error on failure that can be printed with strerror. To do further custom validation and print useful error messages, see query, query* functions, and strpath.

Index

Types

type value_path = struct {
	parent: toml::container,
	location: selector,
};

// Undocumented types:
type selector = (str | size);
type value_type = enum {
	ARRAY,
	TABLE,
	STRING,
	INTEGER,
	FLOAT,
	BOOLEAN,
	DATETIME,
	VOID,
};

Errors

type error = !struct {
	got: value_type,
	expected: value_type,
	path: value_path,
};

Functions

fn get(c: toml::container, path: selector...) toml::value;
fn geta(c: toml::container, path: selector...) (*toml::array | error);
fn getb(c: toml::container, path: selector...) (bool | error);
fn getd(c: toml::container, path: selector...) (date::virtual | error);
fn getf(c: toml::container, path: selector...) (f64 | error);
fn geti(c: toml::container, path: selector...) (i64 | error);
fn gets(c: toml::container, path: selector...) (str | error);
fn gett(c: toml::container, path: selector...) (*toml::table | error);
fn is_missing(e: *error) bool;
fn is_wrong_type(e: *error) bool;
fn query(c: toml::container, path: selector...) ((value_path, toml::value) | void);
fn querya(c: toml::container, path: selector...) ((value_path, *toml::array) | error);
fn queryb(c: toml::container, path: selector...) ((value_path, bool) | error);
fn queryd(c: toml::container, path: selector...) ((value_path, date::virtual) | error);
fn queryf(c: toml::container, path: selector...) ((value_path, f64) | error);
fn queryi(c: toml::container, path: selector...) ((value_path, i64) | error);
fn querys(c: toml::container, path: selector...) ((value_path, str) | error);
fn queryt(c: toml::container, path: selector...) ((value_path, *toml::table) | error);
fn strerror(err: error) str;
fn strpath(path: *value_path) str;
fn trya(c: toml::container, default: *toml::array, path: selector...) (*toml::array | error);
fn tryb(c: toml::container, default: bool, path: selector...) (bool | error);
fn tryd(c: toml::container, default: date::virtual, path: selector...) (date::virtual | error);
fn tryf(c: toml::container, default: f64, path: selector...) (f64 | error);
fn tryi(c: toml::container, default: i64, path: selector...) (i64 | error);
fn trys(c: toml::container, default: str, path: selector...) (str | error);
fn tryt(c: toml::container, default: *toml::table, path: selector...) (*toml::table | error);

Types

type value_path[link]

type value_path = struct {
	parent: toml::container,
	location: selector,
};

Describes a path to a value in a TOML document. You can use it to tell the user where a value is in an error message or similar using strpath.

Bound to the lifetime of the toml::table it's related to.

type selector[link]

Show undocumented member
type selector = (str | size);

type value_type[link]

Show undocumented member
type value_type = enum {
	ARRAY,
	TABLE,
	STRING,
	INTEGER,
	FLOAT,
	BOOLEAN,
	DATETIME,
	VOID,
};

Errors

type error[link]

type error = !struct {
	got: value_type,
	expected: value_type,
	path: value_path,
};

A conflict between the type of a requested value and its actual type. You can print a user-friendly error string from this using strerror.

Bound to the lifetime of the toml::table it's related to.

Functions

fn get[link]

fn get(c: toml::container, path: selector...) toml::value;

Get a value descendent of a container, located at the given path. A string path selector will search a table for a value at the corresponding key, and an integer selector will search an array for a value at the corresponding index.

For example, if the container c were a table, we could call `get(c, "interesting")`, which would return the value in the field "interesting" of the table. We can chain these together. For example, `get(c, "interesting", 2)` would get the "interesting" field of the table, which should be an array, and would then get the item at index 2 of that.

If a vallue matching the path doesn't exist, then void is returned.

fn geta[link]

fn geta(c: toml::container, path: selector...) (*toml::array | error);

Returns the array at the given path if one exists. Returns an error otherwise. See also get.

fn getb[link]

fn getb(c: toml::container, path: selector...) (bool | error);

Returns the boolean at the given path if one exists. Returns an error otherwise. See also get.

fn getd[link]

fn getd(c: toml::container, path: selector...) (date::virtual | error);

Returns the date/time at the given path if one exists. Returns an error otherwise. See also get.

fn getf[link]

fn getf(c: toml::container, path: selector...) (f64 | error);

Returns the float at the given path if one exists. Returns an error otherwise. See also get.

fn geti[link]

fn geti(c: toml::container, path: selector...) (i64 | error);

Returns the integer at the given path if one exists. Returns an error otherwise. See also get.

fn gets[link]

fn gets(c: toml::container, path: selector...) (str | error);

Returns the string at the given path if one exists. Returns an error otherwise. See also get.

fn gett[link]

fn gett(c: toml::container, path: selector...) (*toml::table | error);

Returns the table at the given path if one exists. Returns an error otherwise. See also get.

fn is_missing[link]

fn is_missing(e: *error) bool;

Checks if the error indicates a value is missing.

fn is_wrong_type[link]

fn is_wrong_type(e: *error) bool;

Checks if the error indicates a value was the wrong type.

fn query[link]

fn query(c: toml::container, path: selector...) ((value_path, toml::value) | void);

Same as get, but if the value is found then a tuple is returned, containing the path to the value and the value itself. If the value wasn't found then void is returned.

fn querya[link]

fn querya(c: toml::container, path: selector...) ((value_path, *toml::array) | error);

Returns the table at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn queryb[link]

fn queryb(c: toml::container, path: selector...) ((value_path, bool) | error);

Returns the boolean at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn queryd[link]

fn queryd(c: toml::container, path: selector...) ((value_path, date::virtual) | error);

Returns the date/time at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn queryf[link]

fn queryf(c: toml::container, path: selector...) ((value_path, f64) | error);

Returns the float at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn queryi[link]

fn queryi(c: toml::container, path: selector...) ((value_path, i64) | error);

Returns the integer at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn querys[link]

fn querys(c: toml::container, path: selector...) ((value_path, str) | error);

Returns the string at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn queryt[link]

fn queryt(c: toml::container, path: selector...) ((value_path, *toml::table) | error);

Returns the table at the given path if one exists, along with its value_path. Returns an error otherwise. See also query.

fn strerror[link]

fn strerror(err: error) str;

Converts an error into a user-friendly string. The result may be statically allocated.

fn strpath[link]

fn strpath(path: *value_path) str;

Generates a human-friendly description of the location of a TOML element in a document. The string may be statically alocated.

For example, if we had the following document...

[fruits] apple.varieties = [ "Granny Smith", "Fuji", "golden \n delicious" ]

...And we wanted to print an error message for the "golden delicious" apple variety because the name had a newline in it, we could pass the value_path pointing to it through this function to get the string "fruits.apple.varieties[2]".

fn trya[link]

fn trya(c: toml::container, default: *toml::array, path: selector...) (*toml::array | error);

Returns the array at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.

fn tryb[link]

fn tryb(c: toml::container, default: bool, path: selector...) (bool | error);

Returns the boolean at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.

fn tryd[link]

fn tryd(c: toml::container, default: date::virtual, path: selector...) (date::virtual | error);

Returns the date/time at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.

fn tryf[link]

fn tryf(c: toml::container, default: f64, path: selector...) (f64 | error);

Returns the float at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.

fn tryi[link]

fn tryi(c: toml::container, default: i64, path: selector...) (i64 | error);

Returns the integer at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.

fn trys[link]

fn trys(c: toml::container, default: str, path: selector...) (str | error);

Returns the string at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.

fn tryt[link]

fn tryt(c: toml::container, default: *toml::table, path: selector...) (*toml::table | error);

Returns the table at the given path if one exists. Returns the passed default value if nothing exists at the path. Returns an error otherwise. See also get.