1use std::ffi::OsStr;
2use std::marker::PhantomData;
3
4use ffi;
5use util;
6
7pub struct List<'a, T: 'a, E: 'a> {
14 pub(crate) entry: *mut ffi::udev_list_entry,
15 pub(crate) phantom: PhantomData<&'a (T, E)>,
16}
17
18#[cfg(feature = "send")]
19unsafe impl<T, E> Send for List<'_, T, E> {}
20#[cfg(feature = "sync")]
21unsafe impl<T, E> Sync for List<'_, T, E> {}
22
23pub type EntryList<'a, T> = List<'a, T, Entry<'a>>;
24
25impl<'a, T> Iterator for EntryList<'a, T> {
26 type Item = Entry<'a>;
27
28 fn next(&mut self) -> Option<Entry<'a>> {
29 if self.entry.is_null() {
30 None
31 } else {
32 let name =
33 unsafe { util::ptr_to_os_str_unchecked(ffi::udev_list_entry_get_name(self.entry)) };
34 let value = unsafe { util::ptr_to_os_str(ffi::udev_list_entry_get_value(self.entry)) };
35
36 self.entry = unsafe { ffi::udev_list_entry_get_next(self.entry) };
37
38 Some(Entry { name, value })
39 }
40 }
41
42 fn size_hint(&self) -> (usize, Option<usize>) {
43 (0, None)
44 }
45}
46
47pub struct Entry<'a> {
49 pub(crate) name: &'a OsStr,
50 pub(crate) value: Option<&'a OsStr>,
51}
52
53impl<'a> Entry<'a> {
54 pub fn name(&self) -> &OsStr {
56 self.name
57 }
58
59 pub fn value(&self) -> &OsStr {
61 self.value.unwrap_or_else(|| OsStr::new(""))
62 }
63}