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); }
Methods
impl Pair
[src]
fn new<T: Into<Value>>(key: T) -> Self
[src]
Creates a new Pair.
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");
fn add_slice(&mut self, path: &[Value])
[src]
Recursively adds a slice to a Pair.
fn add_pair(&mut self, pair: Pair)
[src]
Adds a Pair to a Pair.
fn has_key<T>(&self, key: T) -> bool where
Value: From<T>,
[src]
Value: From<T>,
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));
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]));
fn traverse_path(&mut self, path: &[Value]) -> &mut Pair
[src]
Traverses a Pair using a slice, adding the item if it does not exist.
fn get<T>(&mut self, value: T) -> Result<&mut Pair, Box<Error>> where
Value: From<T>,
[src]
Value: From<T>,
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<T>(&self, value: T) -> Result<&Pair, Box<Error>> where
Value: From<T>,
[src]
Value: From<T>,
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();
fn value(&self) -> Option<String>
[src]
Returns the value of a pair as a string.
let config = nccl::parse_file("examples/long.nccl").unwrap(); assert_eq!(config["bool too"].value().unwrap(), "false");
fn value_or(&self, or: String) -> String
[src]
Returns the value of the key or a default value.
fn value_as<T>(&self) -> Result<T, Box<Error>> where
Value: TryInto<T>,
[src]
Value: TryInto<T>,
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());
fn value_as_or<T>(&self, or: T) -> T where
Value: TryInto<T>,
[src]
Value: TryInto<T>,
Gets the value of a key as a specified type or a default value.
fn keys_as<T>(&self) -> Result<Vec<T>, Box<Error>> where
Value: TryInto<T>,
[src]
Value: TryInto<T>,
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]);
fn keys_as_or<T>(&self, or: Vec<T>) -> Vec<T> where
Value: TryInto<T>,
[src]
Value: TryInto<T>,
Gets keys of a value as a vector of T or returns a default vector.
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]
fn clone(&self) -> Pair
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Pair
[src]
impl PartialEq for Pair
[src]
fn eq(&self, __arg_0: &Pair) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Pair) -> bool
[src]
This method tests for !=
.
impl<T> Index<T> for Pair where
Value: From<T>,
[src]
Value: From<T>,
type Output = Pair
The returned type after indexing.
fn index(&self, i: T) -> &Pair
[src]
Performs the indexing (container[index]
) operation.
impl<T> IndexMut<T> for Pair where
Value: From<T>,
[src]
Value: From<T>,