Struct nccl::Pair[][src]

pub struct Pair { /* fields omitted */ }

Struct that contains configuration information.

Examples:

let p = nccl::parse_file("examples/config.nccl").unwrap();
let ports = p["server"]["port"].keys_as::<i64>().unwrap();

println!("Operating on ports:");
for port in ports.iter() {
    println!("  {}", port);
}

Implementations

impl Pair[src]

pub fn new<T: Into<Value>>(key: T) -> Self[src]

Creates a new Pair.

pub fn add<T: Into<Value>>(&mut self, value: T)[src]

Adds a value to a Pair.

Examples:

let mut p = nccl::Pair::new("hello");
p.add(true);
p.add("world");

pub fn add_slice(&mut self, path: &[Value])[src]

Recursively adds a slice to a Pair.

pub fn add_pair(&mut self, pair: Pair)[src]

Adds a Pair to a Pair.

pub fn has_key<T>(&self, key: T) -> bool where
    Value: From<T>, 
[src]

Test if a pair has a key.

Examples:

use nccl::NcclError;
let mut p = nccl::parse_file("examples/config.nccl").unwrap();
assert!(p.has_key("server"));
assert!(p["server"]["port"].has_key(80));

pub fn has_path(&self, path: Vec<Value>) -> bool[src]

Test if a pair has a path of values. Use vec_into! to make this method easier to use.

Examples:

let mut p = nccl::parse_file("examples/config.nccl").unwrap();
assert!(p.has_path(vec_into!["server", "port", 80]));

pub fn traverse_path(&mut self, path: &[Value]) -> &mut Pair[src]

Traverses a Pair using a slice, adding the item if it does not exist.

pub fn get<T>(&mut self, value: T) -> Result<&mut Pair, NcclError> where
    Value: From<T>, 
[src]

Gets a child Pair from a Pair. Used by Pair’s implementation of Index.

let mut p = nccl::Pair::new("top_level");
p.add("hello!");
p.get("hello!").unwrap();

pub fn get_ref<T>(&self, value: T) -> Result<&Pair, NcclError> where
    Value: From<T>, 
[src]

Gets a mutable child Pair from a Pair. Used by Pair’s implementation of IndexMut.

let mut p = nccl::Pair::new("top_level");
p.add(32);
p.get(32).unwrap();

pub fn value(&self) -> Option<String>[src]

Returns the value of a pair as a string. Returns None if the pair is not a leaf.

let config = nccl::parse_file("examples/long.nccl").unwrap();
assert_eq!(config["bool too"].value().unwrap(), "false");

pub fn value_or(&self, or: String) -> String[src]

Returns the value of the key or a default value.

pub fn value_as<T>(&self) -> Result<T, NcclError> where
    Value: TryInto<T>, 
[src]

Gets the value of a key as a specified type, if there is only one.

Examples:

let p = nccl::parse_file("examples/long.nccl").unwrap();
assert!(!p["bool too"].value_as::<bool>().unwrap());

pub fn value_as_or<T>(&self, or: T) -> T where
    Value: TryInto<T>, 
[src]

Gets the value of a key as a specified type or a default value.

pub fn keys_as<T>(&self) -> Result<Vec<T>, NcclError> where
    Value: TryInto<T>, 
[src]

Gets keys of a value as a vector of T.

Examples:

let config = nccl::parse_file("examples/config.nccl").unwrap();
let ports = config["server"]["port"].keys_as::<i64>().unwrap();
assert_eq!(ports, vec![80, 443]);

pub fn keys_as_or<T>(&self, or: Vec<T>) -> Vec<T> where
    Value: TryInto<T>, 
[src]

Gets keys of a value as a vector of T or returns a default vector.

pub fn pretty_print(&self)[src]

Pretty-prints a Pair.

Examples:

let config = nccl::parse_file("examples/config.nccl").unwrap();
config.pretty_print();

// String("__top_level__")
//     String("server")
//         String("domain")
//             String("example.com")
//             String("www.example.com")
//         String("port")
//             Integer(80)
//             Integer(443)
//         String("root")
//             String("/var/www/html")

Trait Implementations

impl Clone for Pair[src]

impl Debug for Pair[src]

impl<T> Index<T> for Pair where
    Value: From<T>, 
[src]

type Output = Pair

The returned type after indexing.

impl<T> IndexMut<T> for Pair where
    Value: From<T>, 
[src]

impl PartialEq<Pair> for Pair[src]

impl StructuralPartialEq for Pair[src]

Auto Trait Implementations

impl RefUnwindSafe for Pair

impl Send for Pair

impl Sync for Pair

impl Unpin for Pair

impl UnwindSafe for Pair

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.