Skip to main content

Crate serde_structprop

Crate serde_structprop 

Source
Expand description

§serde-structprop

A serde serializer and deserializer for the structprop configuration file format — a simple, human-readable format for structured data.

§Format overview

# comment
key = value
key = "value with spaces"
key = 42
key = true

# nested object
section {
    nested_key = value
}

# array of scalars
list = { a b c }

§Quick start

use serde::{Deserialize, Serialize};
use serde_structprop::{from_str, to_string};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Config {
    hostname: String,
    port: u16,
}

// Deserialize
let input = "hostname = localhost\nport = 8080\n";
let cfg: Config = from_str(input).unwrap();
assert_eq!(cfg.hostname, "localhost");
assert_eq!(cfg.port, 8080);

// Serialize
let out = to_string(&cfg).unwrap();
assert!(out.contains("hostname = localhost"));
assert!(out.contains("port = 8080"));

§Module layout

ModuleContents
lexerTokenizer: converts raw text to Tokens
parseRecursive-descent parser: produces a parse::Value tree
deserde::Deserializer implementation
serserde::Serializer implementation
errorError type shared by all modules

Re-exports§

pub use de::from_str;
pub use de::from_value;
pub use error::Error;
pub use error::Result;
pub use parse::parse;
pub use parse::Value;
pub use ser::to_string;

Modules§

de
Serde deserializer for structprop documents. Serde Deserializer for the structprop format.
error
Error type shared by the serializer and deserializer. Error type used throughout serde-structprop.
lexer
Lexer (tokenizer) that converts raw structprop text into tokens. Lexer (tokenizer) for the structprop format.
parse
Parser that converts a token stream into a parse::Value tree. Parser for the structprop format.
ser
Serde serializer for structprop documents. Serde Serializer for the structprop format.