Struct ucl::object::Object [] [src]

pub struct Object {
    // some fields omitted
}

File element object.

This structure is immutable typed reference to object inside parsed tree. It can be one of Type elements and can be cast only to given type.

Methods

impl Object

fn key(&self) -> Option<String>

Return key assigned to object.

fn get_type(&self) -> Type

Return type of object.

fn as_int(&self) -> Option<i64>

Return i64 value

Examples

let obj = ucl::object::Builder::from(10).build();
assert_eq!(obj.as_int(), Some(10));

let obj = ucl::object::Builder::from("lol").build();
assert_eq!(obj.as_int(), None);

fn as_float(&self) -> Option<f64>

Return f64 value

Examples

let obj = ucl::object::Builder::from(10f64).build();
assert_eq!(obj.as_float(), Some(10.0));

let obj = ucl::object::Builder::from("lol").build();
assert_eq!(obj.as_float(), None);

fn as_bool(&self) -> Option<bool>

Return boolean value

Examples

let obj = ucl::object::Builder::from(true).build();
assert_eq!(obj.as_bool(), Some(true));

let obj = ucl::object::Builder::from(10).build();
assert_eq!(obj.as_bool(), None);

fn as_string(&self) -> Option<String>

Return string value

Examples

let obj = ucl::object::Builder::from("lol").build();
assert_eq!(obj.as_string(), Some("lol".to_string()));

let obj = ucl::object::Builder::from(10).build();
assert_eq!(obj.as_string(), None);

fn fetch<T: AsRef<str>>(&self, key: T) -> Option<Object>

Fetch object under key

Examples

let obj = ucl::Parser::new().parse("a = b;").unwrap();
assert_eq!(obj.fetch("a").unwrap().as_string(), Some("b".to_string()));

fn fetch_path<T: AsRef<str>>(&self, path: T) -> Option<Object>

Fetch object at the end of path delimeted by . (dot)

Examples

let obj = ucl::Parser::new().parse("a = { b = c; }").unwrap();
assert_eq!(obj.fetch_path("a.b").unwrap().as_string(), Some("c".to_string()));

Trait Implementations

impl AsRef<Object> for Object

fn as_ref(&self) -> &Self

impl Debug for Object

fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>