Skip to main content

Module toml

Module toml 

Source
Available on crate features parse and toml only.
Expand description

serde TOML integration via the toml crate

Since serde derives requires linking with serde crate, you have to add it to your Cargo.toml:

[dependencies]
serde = "1"
use cu::pre::*; // with `serde` feature, Serialize and Deserialize are
                // part of the prelude

use std::collections::BTreeMap;

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct FooBar {
    foo: BTreeMap<String, String>,
}

// the toml macro and toml module will also be part of the prelude
let value1 = toml! {
    [foo]
    bar = "biz"
};
assert_eq!(value1["foo"]["bar"], "biz".into());
let value2: FooBar = toml::parse(r#"
[foo]
bar = "biz"
"#)?;
assert_eq!(
    Some("biz"),
    value2.foo.get("bar").map(|x| x.as_str()),
);

Structs§

Date
A parsed TOML date value
Datetime
A parsed TOML datetime value
Spanned
A spanned value, indicating the range at which it is defined in the source.
Time
A parsed TOML time value
Toml
TOML parse delegate. See toml

Enums§

Offset
A parsed TOML time offset
Value
Representation of a TOML value.

Functions§

co_readcoroutine
Parse value from an async reader that yields TOML
parse
Parse value from a TOML &str
read
Parse value from a reader that yields TOML
stringify
Convert the value to a TOML string
stringify_pretty
Convert the value to a pretty-formatted TOML string

Type Aliases§

Table
Type representing a TOML table, payload of the Value::Table variant.
Vec
Type representing a TOML array, payload of the Value::Array variant