Skip to main content

NvList

Struct NvList 

Source
pub struct NvList { /* private fields */ }
Expand description

An ordered list of name-value pairs, converted from an illumos nvlist.

Implementations§

Source§

impl NvList

Source

pub unsafe fn from_raw(nvl: *mut nvlist) -> Result<NvList, NvError>

Convert a raw nvlist_t * into an owned NvList.

Pair names and string values are converted from C strings using lossy UTF-8 conversion: any bytes that are not valid UTF-8 are replaced with U+FFFD (\u{FFFD}). This means a lookup() call will not match the original name if it contained non-UTF-8 bytes.

§Safety

nvl must be a valid, non-null pointer to an nvlist. The nvlist is borrowed - the caller retains ownership and is responsible for freeing it.

Source

pub fn lookup(&self, name: &str) -> Option<&NvValue>

Look up a value by name.

Examples found in repository?
examples/list_modules.rs (line 38)
3fn main() {
4    let adm = FmdAdm::open().expect("failed to open fmd adm handle");
5
6    println!("=== FMD Modules ===");
7    let modules = adm.modules().expect("failed to list modules");
8    for m in &modules {
9        println!(
10            "  {} v{} - {}{}",
11            m.name,
12            m.version,
13            m.description,
14            if m.failed { " [FAILED]" } else { "" },
15        );
16    }
17    println!("({} modules total)", modules.len());
18
19    println!("\n=== Faulty Resources ===");
20    let resources = adm.resources(true).expect("failed to list resources");
21    if resources.is_empty() {
22        println!("  (none)");
23    } else {
24        for r in &resources {
25            println!("  {} (case {})", r.fmri, r.uuid);
26        }
27    }
28
29    println!("\n=== Cases ===");
30    let cases = adm.cases(None).expect("failed to list cases");
31    if cases.is_empty() {
32        println!("  (none)");
33    } else {
34        for c in &cases {
35            let severity = c
36                .event
37                .as_ref()
38                .and_then(|e| e.lookup("severity"))
39                .and_then(|v| match v {
40                    NvValue::String(s) => Some(s.as_str()),
41                    _ => None,
42                })
43                .unwrap_or("unknown");
44            println!("  {} - {} (severity: {})", c.uuid, c.code, severity);
45        }
46    }
47}
Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &NvValue)>

Returns an iterator over the name-value pairs.

Source

pub fn len(&self) -> usize

Returns the number of pairs.

Source

pub fn is_empty(&self) -> bool

Returns true if the list contains no pairs.

Trait Implementations§

Source§

impl Clone for NvList

Source§

fn clone(&self) -> NvList

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NvList

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a NvList

Source§

type Item = (&'a str, &'a NvValue)

The type of the elements being iterated over.
Source§

type IntoIter = Map<Iter<'a, (String, NvValue)>, fn(&'a (String, NvValue)) -> (&'a str, &'a NvValue)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a NvList as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for NvList

Source§

type Item = (String, NvValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(String, NvValue)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <NvList as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for NvList

Source§

fn eq(&self, other: &NvList) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for NvList

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.