Rtoml is a toml parser that's designed to
- Acquire values at compile time to a struct.
- Acquire values at runtime required to work.
At the core, a Toml value is represented by this enum
pub enum TomlValue<'a> {
Int(i64),
Float(f64),
String(String),
Array(Vec<TomlValue<'a>>),
Boolean(bool),
DateTime(DateTime),
Table(Table<'a>),
}
For a toml file
[a_table]
value = "hello, world"
We will use the following code to acquire values
use rtoml::prelude::*;
use std::error::Error;
fn main() -> Result<(), TomlError> {
let mut data = String::new();
let mut file = File::open(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/test.toml"))?;
file.read_to_string(&mut data)?;
let toml = TomlValue::try_from(data.as_str())?;
if let Some(table) = toml.as_table() {
if let Some(key_value) = table.get(&TomlKey::from("a_table")) {
assert_eq!(key.get(
TomlKey::from("value"),
TomlValue::Literal(String::from("hello, world"))
))
}
}
Ok(())
}
cargo bench
open ./target/criterion/report/index.html
- Table dot
.
format in table names - Table arrays
- Serialise derive traits
- Use toml testing repo to run all tests
MIT