header-config

Crates.ioheader-config
lib.rsheader-config
version0.1.5
created_at2024-12-21 06:31:14.041733+00
updated_at2025-03-28 20:34:34.737059+00
descriptionRuntime parser for hierarchical configurations using Markdown-style headers
homepage
repositoryhttps://gitlab.com/porky11/header-config
max_upload_size
id1490786
size8,929
Fabio Krapohl (porky11)

documentation

https://docs.rs/header-config

README

Header Config Parser

Crates.io Docs.rs License

A Rust library for parsing hierarchical configuration files using Markdown-style headers, transforming nested sections into flat key-value pairs with namespaced keys.

Features

  • ๐Ÿ“‚ Header-based namespacing
  • โž• Automatic key hierarchy flattening
  • ๐Ÿงน Whitespace-tolerant parsing
  • ๐Ÿšฆ Empty value handling
  • ๐Ÿ” Simple string-based lookups

Installation

Add to your Cargo.toml:

[dependencies]
header-config = "0.1"

File Format Specification

Basic Syntax

# Server Config

port 8080
timeout 30

# Database

host localhost
user admin

## Replica

host replica.db

Key Features

  • Headers create namespaces using # symbols
  • Keys are whitespace-separated from values
  • Empty values allowed (key without value)
  • Nesting with subheaders (## Subsection)

Parsing Rules

  • Header levels determine namespace depth
  • It's not allowed to go more than one header level deeper at once
  • Keys inherit all parent header namespaces
  • Case-sensitive matching
  • Duplicates aren't allowed

Example

The format looks like this:

key1 value
key2

# HeaderA

key1 value
key2

# HeaderB

key1 value
key2

## SubheaderA

key1 value
key2

## SubheaderB

key1 value
key2

The created mapping will be something like this:

"key1" -> "value"
"key2" -> ""
"HeaderA:key1" -> "value"
"HeaderA:key2" -> ""
"HeaderB:key1" -> "value"
"HeaderB:key2" -> ""
"HeaderB:SubheaderA:key1" -> "value"
"HeaderB:SubheaderA:key2" -> ""
"HeaderB:SubheaderB:key1" -> "value"
"HeaderB:SubheaderB:key2" -> ""
Commit count: 0

cargo fmt