1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Macros for building values in code.
/// Builds a [`Table`](crate::Table) from `key => value` pairs.
///
/// Keys are anything that converts into a `String`, values anything that
/// converts into a [`Value`](crate::Value) -- including a nested `table!`.
///
/// ```
/// use tomlproc::{table, array};
///
/// let doc = table! {
/// "title" => "TOML Example",
/// "owner" => table! {
/// "name" => "Tom Preston-Werner",
/// "ports" => array![8000, 8001],
/// },
/// };
///
/// assert_eq!(doc["owner"]["ports"][1].as_integer(), Some(8001));
/// assert_eq!(tomlproc::table!().len(), 0);
/// ```
///
/// To build a document from literal TOML syntax instead, parse it:
/// `tomlproc::parse(r#"…"#)`.
/// Builds an array [`Value`](crate::Value) whose elements need not share a
/// type.
///
/// `Value::from(vec![…])` covers the same-type case; this one exists for the
/// mixed arrays TOML 1.0 allows.
///
/// ```
/// use tomlproc::array;
///
/// let mixed = array![1, "two", 3.0, array![4]];
/// assert_eq!(mixed[1].as_str(), Some("two"));
/// assert_eq!(array![].as_array().map(Vec::len), Some(0));
/// ```