nested_text/lib.rs
1//! A fully spec-compliant [NestedText](https://nestedtext.org) v3.8 parser and serializer.
2//!
3//! NestedText is a data format similar to YAML but with no type ambiguity — all leaf
4//! values are strings. No quoting, no escaping, no type coercion surprises.
5//!
6//! # Quick start
7//!
8//! ```rust
9//! use nested_text::{loads, dumps, Top, DumpOptions};
10//!
11//! let input = "name: Alice\nage: 30\n";
12//! let value = loads(input, Top::Any).unwrap().unwrap();
13//!
14//! assert_eq!(value.get("name").unwrap().as_str(), Some("Alice"));
15//!
16//! let output = dumps(&value, &DumpOptions::default());
17//! let roundtripped = loads(&output, Top::Any).unwrap().unwrap();
18//! assert_eq!(value, roundtripped);
19//! ```
20//!
21//! # serde support
22//!
23//! Enabled by default via the `serde` feature. Since NestedText only has string
24//! scalars, numeric and boolean fields are parsed from their string representation.
25//!
26//! ```rust
27//! use serde::Deserialize;
28//!
29//! #[derive(Deserialize)]
30//! struct Config {
31//! name: String,
32//! debug: bool,
33//! port: u16,
34//! }
35//!
36//! let config: Config = nested_text::from_str("name: app\ndebug: true\nport: 8080").unwrap();
37//! assert_eq!(config.port, 8080);
38//! ```
39//!
40//! # Features
41//!
42//! - **`serde`** (default) — enables [`from_str`] and [`to_string`] for serde integration
43
44mod dumper;
45mod error;
46mod inline;
47mod lexer;
48mod parser;
49mod value;
50
51#[cfg(feature = "serde")]
52mod de;
53#[cfg(feature = "serde")]
54mod ser;
55
56pub use dumper::{dump, dumps, DumpOptions};
57pub use error::{Error, ErrorKind};
58pub use parser::{load, loads, Top};
59pub use value::Value;
60
61#[cfg(feature = "serde")]
62pub use de::from_str;
63#[cfg(feature = "serde")]
64pub use ser::{to_string, to_string_with_options};