Struct Parser

Source
pub struct Parser { /* private fields */ }

Implementations§

Source§

impl Parser

Source

pub fn new() -> Self

Create new parser instance with default options

Source

pub 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 = libucl::Parser::with_flags(libucl::parser::Flags::LOWERCASE);
let doc = parser.parse("A = b").unwrap();

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

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

Parse given string. Returns root object on success.

It moves out Parser.

§Examples
assert!(libucl::Parser::new().parse("a = b").is_ok());
assert!(libucl::Parser::new().parse("a =").is_err());
Source

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

Parse file at given Path.

Source

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

Register new variable

§Examples
let p = libucl::Parser::new();
p.register_var("someVar".to_string(), "test_string".to_string());
let res = p.parse("testVar = $someVar").unwrap();

assert_eq!(res.fetch("testVar").unwrap().as_string(), Some("test_string".to_string()));

Trait Implementations§

Source§

impl Drop for Parser

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl RefUnwindSafe for Parser

§

impl !Send for Parser

§

impl !Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.