libucl 0.2.1

Rust wrapper with bindings to libucl
docs.rs failed to build libucl-0.2.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: libucl-0.2.3

UCL (Universal Configuration Library)

This library is parser for UCL files.

Basic structure

UCL provide support for 2 different syntaxes:

  • JSON
{
"param": "value",
"section": {
"flag": true,
"number": 10000,
"subsection": {
"hosts": [
{
"host": "localhost",
"port": 9000
},
{
"host": "remotehost",
"port": 9090
}
}
}
}
  • nginx like UCL
param = value;
section {
flag = true;
number = 10k;
subsection {
hosts = {
host = "localhost";
port = 9000
}
hosts = {
host = "remotehost"
port = 9090
}
}
}

Differences between UCL and JSON:

  • outmost braces are optional so {"a": "b"} is equivalent to "a": "b"
  • quotes on keys and strings are optional
  • : can be replaced with = or even skipped for objects
  • comma can be replaced with semicolon
  • trailing commas are allowed
  • automatic array creation - non-unique keys in object are allowed and are automatically converted to arrays

Parser usage

Simple example:

static DOC: &'static str = r#"
param = value;
section {
flag = true;
number = 10k;
subsection {
hosts = {
host = "localhost";
port = 9000
}
hosts = {
host = "remotehost"
port = 9090
}
}
}
"#;

let parser = libucl::Parser::new();
let document = parser.parse(DOC).unwrap();

assert_eq!(document.fetch("param").unwrap().as_string(), Some("value".to_string()));