Skip to main content

Crate tanzim_parse

Crate tanzim_parse 

Source
Expand description

§tanzim-parse

Second stage of the tanzim pipeline: deserializes raw bytes into typed, source-located value trees.

§The Deserialize trait

Implement Deserialize to add a new configuration format. Every node in the returned LocatedValue tree should carry a Location pointing to the source file and line for accurate error messages.

§Built-in parsers

TypeFeatureFormats
Envenvenv
Jsonjsonjson
Yamlyamlyml, yaml
Tomltomltoml
closure::Closurecustom

§Example

use tanzim_parse::{Deserialize, Json};

fn main() -> Result<(), tanzim_value::Error> {
    let value = Json::new().parse("file", "config.json", br#"{"port": 8080}"#)?;
    let map = value.value.as_map().unwrap();
    let port = map.get("port").unwrap();
    println!("port={port}  location={}", port.location);
    Ok(())
}

§Features

FeatureEnables
envenv format parser (KEY=VALUE lines)
jsonJSON parser with source spans
yamlYAML parser with line numbers
tomlTOML parser with source spans
loggingemit log messages via the log crate
tracingemit trace spans via the tracing crate
fullenv + json + yaml + toml

Default features: logging, env.

§Relations

Modules§

closure
Custom parser backed by a closure.

Structs§

Env
Json
LocatedValue
A Value with its Location.
Toml
Yaml

Enums§

Error
Error while deserializing configuration input.
Value
Dynamically typed configuration value (six variants, no null).

Traits§

Deserialize
Deserializes raw bytes into a LocatedValue tree for one format.