Crates.io | gtoml |
lib.rs | gtoml |
version | 0.1.2 |
created_at | 2025-03-23 06:15:26.975028+00 |
updated_at | 2025-03-23 06:19:47.642266+00 |
description | Get TOML values quickly |
homepage | http://dnrops.gitlink.net |
repository | https://gitlab.com/andrew_ryan/gtoml |
max_upload_size | |
id | 1602375 |
size | 19,093 |
Get TOML values quickly
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.
Add the following to your Cargo.toml
:
[dependencies]
gtoml = "0.1"
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.
toml::Value
type.Value
using a specified path.*
and ?
wildcards in the path for matching.use toml::Value;
use gtoml::parse;
let toml_str = r#"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
"#;
let value = parse(toml_str).unwrap();
use toml::Value;
use gtoml::{parse, get};
let toml_str = r#"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
"#;
let value = parse(toml_str).unwrap();
let result = get(&value, "owner.name").unwrap();
use toml::Value;
use gtoml::get_from_str;
let toml_str = r#"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00Z
"#;
let result = get_from_str(toml_str, "owner.name").unwrap();
You can use *
and ?
wildcards in the path for matching:
use toml::Value;
use gtoml::{parse, get};
let toml_str = r#"
children = ["Sara", "Alex", "Jack"]
"#;
let value = parse(toml_str).unwrap();
let result = get(&value, "child*").unwrap();
To get the length of an array, use #
in the path:
use toml::Value;
use gtoml::{parse, get};
let toml_str = r#"
children = ["Sara", "Alex", "Jack"]
"#;
let value = parse(toml_str).unwrap();
let result = get(&value, "children.#").unwrap();
This library includes a series of test cases. You can run the tests with the following command:
cargo test