serde-structprop
A serde serializer and deserializer for the structprop configuration file format — a simple, human-readable format for structured data.
Format overview
Structprop files are composed of three constructs:
# Lines beginning with # are comments (inline comments are also supported)
# Scalar key-value pair
key = value
key = "value with spaces or special chars"
key = 42
key = true
# Nested object block
section {
nested_key = value
another = 123
}
# Array of scalars
list = { a b c }
list = {
a
b
c
}
Special characters in values (spaces, tabs, #, {, }, =) must be
wrapped in double quotes. Keys follow the same rule.
Installation
Add to your Cargo.toml:
[]
= { = "1", = ["derive"] }
= "0.1"
Type mapping
| Rust / serde type | Structprop representation |
|---|---|
bool |
true or false |
| integer / float | bare numeric scalar |
String / &str |
bare scalar, or "quoted" when it contains special chars |
Option<T> (Some) |
the inner value |
Option<T> (None) / () |
null |
| struct / map | key { … } block |
Vec<T> / sequence |
key = { … } list |
| unit enum variant | bare variant name |
| newtype / tuple / struct enum variant | variant_name { … } block |
raw &[u8] |
unsupported — returns Error::UnsupportedType |
Quick start
Deserializing
use Deserialize;
use from_str;
Serializing
use Serialize;
use to_string;
Nested structs
use ;
use ;
Quoted values
Values containing spaces or structprop special characters (#, {, }, =)
must be quoted in the input and are quoted automatically on output:
use ;
use ;
Optional fields
use ;
use from_str;
Error handling
All functions return serde_structprop::Result<T>, an alias for
std::result::Result<T, serde_structprop::Error>.
use ;
match
Error variants
| Variant | When |
|---|---|
Error::Parse(String) |
Lexer or parser encountered unexpected input |
Error::Message(String) |
serde type mismatch (e.g. string where integer expected) |
Error::UnsupportedType(&str) |
Type has no structprop equivalent (e.g. &[u8]) |
Error::KeyMustBeString |
A map was serialized with a non-string key |
Module layout
| Module | Contents |
|---|---|
serde_structprop::de |
Deserializer implementation; from_str entry point |
serde_structprop::ser |
Serializer implementation; to_string entry point |
serde_structprop::parse |
Recursive-descent parser; Value AST enum |
serde_structprop::lexer |
Tokenizer; Token enum |
serde_structprop::error |
Error enum and Result<T> alias |
License
Licensed under either of
at your option.