Skip to main content

serde_structprop/
lib.rs

1//! # serde-structprop
2//!
3//! A [serde](https://serde.rs/) serializer and deserializer for the
4//! [structprop](https://github.com/edgeware/structprop) configuration file
5//! format — a simple, human-readable format for structured data.
6//!
7//! ## Format overview
8//!
9//! ```text
10//! # comment
11//! key = value
12//! key = "value with spaces"
13//! key = 42
14//! key = true
15//!
16//! # nested object
17//! section {
18//!     nested_key = value
19//! }
20//!
21//! # array of scalars
22//! list = { a b c }
23//! ```
24//!
25//! ## Quick start
26//!
27//! ```rust
28//! use serde::{Deserialize, Serialize};
29//! use serde_structprop::{from_str, to_string};
30//!
31//! #[derive(Debug, Serialize, Deserialize, PartialEq)]
32//! struct Config {
33//!     hostname: String,
34//!     port: u16,
35//! }
36//!
37//! // Deserialize
38//! let input = "hostname = localhost\nport = 8080\n";
39//! let cfg: Config = from_str(input).unwrap();
40//! assert_eq!(cfg.hostname, "localhost");
41//! assert_eq!(cfg.port, 8080);
42//!
43//! // Serialize
44//! let out = to_string(&cfg).unwrap();
45//! assert!(out.contains("hostname = localhost"));
46//! assert!(out.contains("port = 8080"));
47//! ```
48//!
49//! ## Module layout
50//!
51//! | Module | Contents |
52//! |---|---|
53//! | [`lexer`] | Tokenizer: converts raw text to `Token`s |
54//! | [`mod@parse`] | Recursive-descent parser: produces a [`parse::Value`] tree |
55//! | [`de`] | `serde::Deserializer` implementation |
56//! | [`ser`] | `serde::Serializer` implementation |
57//! | [`error`] | [`Error`] type shared by all modules |
58
59#![deny(clippy::all, clippy::pedantic)]
60#![deny(missing_docs)]
61
62/// Serde deserializer for structprop documents.
63pub mod de;
64/// Error type shared by the serializer and deserializer.
65pub mod error;
66/// Lexer (tokenizer) that converts raw structprop text into tokens.
67pub mod lexer;
68/// Parser that converts a token stream into a [`parse::Value`] tree.
69pub mod parse;
70/// Serde serializer for structprop documents.
71pub mod ser;
72
73pub use de::{from_str, from_value};
74pub use error::{Error, Result};
75pub use parse::{parse, Value};
76pub use ser::to_string;