Struct nccl::Pair [−][src]
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]
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));
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]
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();
pub fn get_ref<T>(&self, value: T) -> Result<&Pair, NcclError> 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();
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]
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());
pub 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.
pub fn keys_as<T>(&self) -> Result<Vec<T>, NcclError> 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]);
pub 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.
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]
Value: From<T>,
impl<T> IndexMut<T> for Pair where
Value: From<T>,
[src]
Value: From<T>,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,