gtoml
gtoml is a Rust crate that offers a fast and simple way to retrieve values from a TOML document. It comes with features such as one-line retrieval, dot notation paths, and iteration.
Getting Started
Usage
Add the following to your Cargo.toml:
[]
= "0.1"
TOML Parser and Value Retrieval Library
Overview
This is a Rust library designed to parse TOML strings and retrieve values based on specified paths. It supports basic TOML parsing, path-based value lookup, array length retrieval, and wildcard matching.
Features
- TOML Parsing: It can parse a TOML string into a
toml::Valuetype. - Value Retrieval: Retrieve values from the parsed
Valueusing a specified path. - Wildcard Support: Supports the use of
*and?wildcards in the path for matching. - Array Length Retrieval: Retrieve the length of an array.
How to Use
Parse a TOML String
use Value;
use parse;
let toml_str = r#"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
"#;
let value = parse.unwrap;
Retrieve a Value by Path
use Value;
use ;
let toml_str = r#"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
"#;
let value = parse.unwrap;
let result = get.unwrap;
Retrieve a Value Directly from a TOML String
use Value;
use get_from_str;
let toml_str = r#"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
"#;
let result = get_from_str.unwrap;
Using Wildcards
You can use * and ? wildcards in the path for matching:
use Value;
use ;
let toml_str = r#"
children = ["Sara", "Alex", "Jack"]
"#;
let value = parse.unwrap;
let result = get.unwrap;
Retrieving Array Length
To get the length of an array, use # in the path:
use Value;
use ;
let toml_str = r#"
children = ["Sara", "Alex", "Jack"]
"#;
let value = parse.unwrap;
let result = get.unwrap;
Testing
This library includes a series of test cases. You can run the tests with the following command: