gtoml 0.1.2

Get TOML values quickly
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 19.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 358.75 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 32s Average build duration of successful builds.
  • all releases: 31s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zinso

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:

[dependencies]

gtoml = "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

  1. TOML Parsing: It can parse a TOML string into a toml::Value type.
  2. Value Retrieval: Retrieve values from the parsed Value using a specified path.
  3. Wildcard Support: Supports the use of * and ? wildcards in the path for matching.
  4. Array Length Retrieval: Retrieve the length of an array.

How to Use

Parse a TOML String

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();

Retrieve a Value by Path

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();

Retrieve a Value Directly from a TOML String

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();

Using Wildcards

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();

Retrieving Array Length

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();

Testing

This library includes a series of test cases. You can run the tests with the following command:

cargo test