libucl 0.2.2

Rust wrapper with bindings to libucl
docs.rs failed to build libucl-0.2.2
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

Rust wrapper around libucl

MIT Licensed

A lightweight wrapper library in Rust around libucl, a library used for parsing of UCL (Universal Configuration Language) files.

Basics

You can read all about UCL (Universal Configuration Language) here

Usage

use libucl::Parser;

let parser = Parser::new();
let result = parser.parse(r#"tag = "svc";
upstream {
    h2c = true;
    host = "http://localhost";
    port = 9090;
    connect_timeout = 1s;
}"#).unwrap();

println!("{}", result.fetch_path("upstream.h2c").and_then(|v| v.as_bool()));

Validation

You can write validation schemas in UCL format as well, as long as it follows the JSON Schema rules for defining a schema with the exception of remote references. UCL currently is not absolutely strict about validation schemas themselves, therefore UCL users should supply valid schemas (as it is defined in json-schema draft v4) to ensure that the input objects are validated properly.

use libucl::Parser;

let parser = Parser::new();
let item = parser.parse(r#"
    {
    "key": "some string"
    }"#
).unwrap();

let parser = Parser::new();
let schema = parser.parse(r#"
    {
    "type": "object",
     "properties":{
        "key": {
            "type":"string"
            }
        }
    }"#
    ).unwrap();
let res = item.validate_with_schema(&schema);
assert_eq!(res.is_ok(), true);

Instalation

In your Cargo.toml file under [dependencies] add libucl = "0.2.1"

Licence

Check out LICENSE file.