Struct libnv::libnv::NvList[][src]

pub struct NvList { /* fields omitted */ }
Expand description

A list of name/value pairs.

Implementations

Make a copy of a pointer. Danger zone.

Create a new name/value pair list (nvlist). Call this can only fail when system is out of memory.

use libnv::libnv::{NvList, NvFlag};

let nvlist = NvList::new(NvFlag::None).unwrap();

Determines if the nvlist is empty.

use libnv::libnv::{NvList, NvFlag};
let nvlist = NvList::new(NvFlag::IgnoreCase).unwrap();
assert!(nvlist.is_empty());

The flags the nvlist was created with.

use libnv::libnv::{NvList, NvFlag};
let nvlist = NvList::new(NvFlag::NoUnique).unwrap();

assert_eq!(nvlist.flags(), NvFlag::NoUnique);

Gets error value that the list may have accumulated.

use libnv::libnv::{NvList, NvFlag};
let list = NvList::new(NvFlag::NoUnique).unwrap();

assert_eq!(0, list.error());

Sets the NvList to be in an error state.

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::Both).unwrap();

// EINVAL
list.set_error(0x16).unwrap();

assert_eq!(0x16, list.error());

Sugared way to add a single value to the NvList.

use libnv::libnv::{NvList, NvFlag, NvTypeOp};

let mut list = NvList::default();

let the_answer: u32 = 1776;
let not_the_answer: Option<u64> = None;

list.insert("Important year", the_answer);
list.insert("not important year", not_the_answer);
let copy = list.clone();
list.insert("foo", copy);

assert_eq!(list.get_number("Important year").unwrap().unwrap(), 1776);

Add a null value to the NvList.

use libnv::libnv::{NvList, NvFlag, NvTypeOp};
let mut list = NvList::new(NvFlag::Both).unwrap();
list.insert_null("Hello, World!");

Add a number to the NvList. Number will be converted into u64.

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::Both).unwrap();

list.insert_number("Important year", 1776u64);

Add a bool to the list.

Add string to the list.

Add NvList to the list.

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::default();

let other_list = NvList::default();

list.insert_nvlist("other list", &other_list).unwrap();

Add binary data to the list. TODO: make this safe.

Add an array of bool values.

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::Both).unwrap();

let slice = [true, false, true, false];

list.insert_bools("Important year", &slice);

Add an array if u64. TODO: Make it work with any number…

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::None).unwrap();

let slice = [1776, 2017];

list.insert_numbers("Important year", &slice);

Add an array of strings

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::None).unwrap();

let orig = ["Hello", "World!"];

list.insert_strings("key", &orig).unwrap();

let vec = list.get_strings("key").unwrap().unwrap();

assert_eq!(*vec, ["Hello", "World!"]);

Add an array of NvLists

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::Both).unwrap();

let slice = [NvList::new(NvFlag::Both).unwrap(),
NvList::new(NvFlag::Both).unwrap(),
             NvList::new(NvFlag::None).unwrap()];

list.insert_nvlists("nvlists", &slice);

let mut nvlists = list.get_nvlists("nvlists").unwrap().unwrap();

assert_eq!(NvFlag::None, nvlists.pop().unwrap().flags());

Returns true if a name/value pair exists in the NvList and false otherwise.

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::Both).unwrap();

let result = list.insert_number("Important year", 1776u64);
assert!(result.is_ok());

assert!(list.contains_key("Important year").unwrap());

Returns true if a name/value pair of the specified type exists and false otherwise.

use libnv::libnv::{NvList, NvFlag, NvType};

let mut list = NvList::new(NvFlag::Both).unwrap();

let result = list.insert_number("Important year", 1776u64);
assert!(result.is_ok());

assert!(!list.contains_key_with_type("Important year", NvType::Bool).unwrap());

Get the first matching bool value paired with the given name.

use libnv::libnv::NvList;

let mut list = NvList::default();

list.insert_bool("Did history start on 1776?", true).unwrap();

assert!(list.get_bool("Did history start on 1776?").unwrap().unwrap(),
true);

Get the first matching u64 value paired with the given name.

Get the first matching u64 value paired with the given name

use libnv::libnv::{NvList, NvFlag};

// Note: we're allowing duplicate values per name
let mut list = NvList::default();

list.insert_string("Hello", "World!").unwrap();

assert_eq!(list.get_string("Hello").unwrap().unwrap(), "World!");

Get the first matching NvList value paired with the given name and clone it

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::Both).unwrap();

list.insert_bool("other list", true).unwrap();

let mut other_list = NvList::new(NvFlag::None).unwrap();
other_list.insert_number("Important year", 42u32).unwrap();

list.insert_nvlist("other list", &other_list).unwrap();

// Since we use `get_nvlist` we will get the
// NvList not the boolean value
let other_nvlist = list.get_nvlist("other list").unwrap().unwrap();

assert_eq!(other_nvlist.get_number("Important year").unwrap().unwrap(),
42);

Get a &[bool] from the NvList

use libnv::libnv::{NvList, NvFlag};

// Note: we're allowing duplicate values per name
let mut list = NvList::new(NvFlag::None).unwrap();

list.insert_bools("true/false", &[true, false, true]).unwrap();

assert_eq!(list.get_bools("true/false").unwrap().unwrap(), &[true,
false, true]);

Get a &[u64] slice from the NvList

use libnv::libnv::{NvList, NvFlag};

// Note: we're allowing duplicate values per name
let mut list = NvList::default();

list.insert_numbers("The Year", &[1, 7, 7, 6]).unwrap();

assert_eq!(list.get_numbers("The Year").unwrap().unwrap(), &[1, 7, 7,
6]);

Get a Vec<String> of the first string slice added to the NvList for the given name

Get an array of NvList.

use libnv::libnv::{NvList, NvFlag};

let mut list = NvList::new(NvFlag::None).unwrap();

list.insert_nvlists("lists", &[NvList::default(),
                                      NvList::default()]).unwrap();

let vec = list.get_nvlists("lists").unwrap().unwrap();

assert_eq!(vec.len(), 2);
assert_eq!(vec[0].flags(), NvFlag::None);

Write NvList to a file descriptor.

use std::fs::File;
use libnv::libnv::NvList;

let mut list = NvList::default();

list.insert_number("Important year", 1776u64);

list.dump(File::create("/tmp/libnv_nv.dump").unwrap());

The size of the current list

Removes a key from the NvList.

Remove the element of the given name and type from the NvList

Trait Implementations

Clone list using libnv method. This will perform deep copy.

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Using libnv method.

Add a $type_ value to the NvList

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.