Struct ucl::parser::Parser [] [src]

pub struct Parser {
    // some fields omitted
}

Methods

impl Parser

fn new() -> Self

Create new parser instance with default options

fn with_flags(flags: Flags) -> Self

Create new parser with given option flags

Flags:

  • DEFAULT - default configuration
  • LOWERCASE - convert all keys to lower case
  • ZEROCOPY - parse input in zero-copy mode if possible (you must ensure that input memory is not freed if an object is in use)
  • NO_TIME - do not parse time and treat it's value as string
  • NO_IMPLICIT_ARRAYS - create explicit arrays instead of implicit ones

Examples

let parser = ucl::Parser::with_flags(ucl::parser::LOWERCASE);
let doc = parser.parse("A = b").unwrap();

assert!(doc.fetch("a").is_some());

fn parse<T: AsRef<str>>(self, string: T) -> Result<Object>

Parse given string. Returns root object on success.

It moves out Parser.

Examples

assert!(ucl::Parser::new().parse("a = b").is_ok());
assert!(ucl::Parser::new().parse("a =").is_err());

fn parse_file<T: AsRef<Path>>(self, path: T) -> Result<Object>

Parse file at given Path.

It moves out Parser.

fn register_var(&self, name: String, value: String)

Register new variable

Examples

let p = ucl::Parser::new();
p.register_var("LOL".to_string(), "test".to_string());
let res = p.parse("lol = $LOL").unwrap();

assert_eq!(res.fetch("lol").unwrap().as_string(), Some("test".to_string()));

Trait Implementations

impl Drop for Parser

fn drop(&mut self)