Skip to main content

Crate nested_text

Crate nested_text 

Source
Expand description

A fully spec-compliant NestedText v3.8 parser and serializer.

NestedText is a data format similar to YAML but with no type ambiguity — all leaf values are strings. No quoting, no escaping, no type coercion surprises.

§Quick start

use nested_text::{loads, dumps, Top, DumpOptions};

let input = "name: Alice\nage: 30\n";
let value = loads(input, Top::Any).unwrap().unwrap();

assert_eq!(value.get("name").unwrap().as_str(), Some("Alice"));

let output = dumps(&value, &DumpOptions::default());
let roundtripped = loads(&output, Top::Any).unwrap().unwrap();
assert_eq!(value, roundtripped);

§serde support

Enabled by default via the serde feature. Since NestedText only has string scalars, numeric and boolean fields are parsed from their string representation.

use serde::Deserialize;

#[derive(Deserialize)]
struct Config {
    name: String,
    debug: bool,
    port: u16,
}

let config: Config = nested_text::from_str("name: app\ndebug: true\nport: 8080").unwrap();
assert_eq!(config.port, 8080);

§Features

Structs§

DumpOptions
Options for controlling NestedText output formatting.
Error
Error type with location information matching the NestedText test suite format.

Enums§

ErrorKind
Top
Constraint on the top-level type of a NestedText document.
Value
The three NestedText value types.

Functions§

dump
Serialize a Value to a writer in NestedText format.
dumps
Serialize a Value to a NestedText string.
from_str
Deserialize a NestedText string into a type that implements Deserialize.
load
Parse a NestedText document from a reader.
loads
Parse a NestedText string into a Value.
to_string
Serialize a value to a NestedText string.
to_string_with_options
Serialize a value to a NestedText string with custom options.