Created
September 21, 2019 23:56
-
-
Save andoriyu/ae581c3d747c05375cde349a84fad7e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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