Expand description
§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()));Re-exports§
pub use error::UclError;pub use error::UclSchemaError;pub use parser::Parser;pub use object::Object;pub use object::emitter::Emitter;