hocon 0.2.0

Reads HOCON configuration files
Documentation

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 = HoconLoader::from_str(s).unwrap();

assert_eq!(doc["a"].as_i64().unwrap(), 5);
let s = r#"{"b":5, "b":10}"#;
let doc: Hocon = HoconLoader::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
  • object concatenation
  • array concatenation
  • path expressions
  • path as keys
  • substitutions
  • includes
  • conversion of numerically-indexed objects to arrays
  • allow URL for included files
  • duration unit format
  • period unit format
  • size unit format