2 releases

✓ Uses Rust 2018 edition

0.1.1 Feb 9, 2019
0.1.0 Feb 3, 2019

#58 in Configuration

Download history 34/week @ 2019-02-02

18 downloads per month

MIT license

54KB
1.5K SLoC

HOCON.rs License: MIT Build Status Coverage Status Realease Doc Crate

Parse HOCON configuration files in Rust

The API docs for the master branch are published here.

Usage

let s = r#"{"a":5}"#;
let doc = Hocon::load_from_str(s).unwrap();

assert_eq!(doc["a"].as_i64().unwrap(), 5);
let s = r#"{"b":5, "b":10}"#;
let doc = Hocon::load_from_str(s).unwrap();

assert_eq!(doc["b"].as_i64().unwrap(), 10);

Serde support is enabled by default and can be used to deserialize HOCON documents to structs. It can be disabled by disabling default features.

use serde::Deserialize;

#[derive(Deserialize)]
struct Configuration {
    host: String,
    port: u8,
    auto_connect: bool,
}

let s = r#"{host: 127.0.0.1, port: 80, auto_connect: false}"#;

let conf: Configuration = hocon::serde::from_str(s).unwrap();

Status

https://github.com/lightbend/config/blob/master/HOCON.md

  • parsing JSON
  • comments
  • omit root braces
  • key-value separator
  • commas are optional if newline is present
  • whitespace
  • duplicate keys and object merging
  • unquoted strings
  • multi-line strings
  • value concatenation
  • path expressions
  • path as keys
  • substitutions
  • includes
  • conversion of numerically-indexed objects to arrays

Dependencies

~684KB
~16K SLoC