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::<u32>().unwrap(); println!("Operating on ports:"); for port in ports.iter() { println!(" {}", port); }
Methods
impl Pair
[src]
fn new(key: &str) -> Self
Creates a new Pair.
fn add(&mut self, value: &str)
Adds a value to a Pair.
Examples:
let mut p = nccl::Pair::new("hello"); p.add("world");
fn add_slice(&mut self, path: &[String])
Recursively adds a slice to a Pair.
fn add_pair(&mut self, pair: Pair)
Adds a Pair to a Pair.
fn has_key(&self, key: &str) -> bool
Test if a pair has a key.
Examples:
let p = nccl::parse_file("examples/config.nccl").unwrap(); assert!(p.has_key("server"));
fn traverse_path(&mut self, path: &[String]) -> &mut Pair
Traverses a Pair using a slice, adding the item if it does not exist.
fn get(&mut self, value: &str) -> Result<&mut Pair, Box<Error>>
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();
fn get_ref(&self, value: &str) -> Result<&Pair, Box<Error>>
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("hello!"); p.get("hello!").unwrap();
fn value(&self) -> Option<String>
Gets the value of a key if there is only one.
Examples:
let p = nccl::parse_file("examples/config.nccl").unwrap(); assert_eq!(p["server"]["root"].value().unwrap(), "/var/www/html");
fn value_as<T>(&self) -> Result<T, Box<Error>> where
T: FromStr,
T: FromStr,
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_eq!(p["bool too"].value_as::<bool>().unwrap(), false);
fn keys(&self) -> Vec<String>
Gets keys of a value as a vector of Strings.
Examples:
let v: Vec<String> = vec!["bologne".into(), "ham".into()]; let p = nccl::parse_file("examples/inherit.nccl").unwrap(); assert_eq!(p["sandwich"]["meat"].keys(), v);
fn keys_as<T: FromStr>(&self) -> Result<Vec<T>, Box<Error>>
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::<i32>().unwrap(); assert_eq!(ports, vec![80, 443]);
fn pretty_print(&self)
Pretty-prints a Pair.
Trait Implementations
impl Clone for Pair
[src]
fn clone(&self) -> Pair
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for Pair
[src]
impl PartialEq for Pair
[src]
fn eq(&self, __arg_0: &Pair) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Pair) -> bool
This method tests for !=
.
impl<'a> Index<&'a str> for Pair
[src]
type Output = Pair
The returned type after indexing
fn index(&self, i: &str) -> &Pair
The method for the indexing (container[index]
) operation