Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created September 21, 2019 23:56
Show Gist options
  • Save andoriyu/ae581c3d747c05375cde349a84fad7e6 to your computer and use it in GitHub Desktop.
Save andoriyu/ae581c3d747c05375cde349a84fad7e6 to your computer and use it in GitHub Desktop.
pub struct NvList {
ptr: *mut sys::nvlist_t,
}
pub struct NvPair {
ptr: *mut sys::nvpair_t,
}
impl NvPair {
pub unsafe fn from_ptr(ptr: *mut sys::nvpair_t) -> NvPair {
NvPair {
ptr
}
}
}
pub struct Iter<'a> {
list:&'a NvList,
position: *mut sys::nvpair_t,
}
impl<'a> Iterator for Iter<'a> {
type Item = &'a NvPair;
fn next(&mut self) -> Option<Self::Item> {
let next = unsafe { sys::nvlist_next_nvpair(self.list.as_ptr(), self.position) };
self.position = next;
if next.is_null() {
None
} else {
Some(unsafe { &'a NvPair::from_ptr(next) })
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment