1use std::ffi::{CStr, CString};
2use std::marker::PhantomData;
3use std::ptr;
4use std::str::from_utf8_unchecked;
5
6use ffi::*;
7
8pub struct Iter<'a> {
9 ptr: *const AVDictionary,
10 cur: *mut AVDictionaryEntry,
11
12 _marker: PhantomData<&'a ()>,
13}
14
15impl<'a> Iter<'a> {
16 pub fn new(dictionary: *const AVDictionary) -> Self {
17 Iter {
18 ptr: dictionary,
19 cur: ptr::null_mut(),
20
21 _marker: PhantomData,
22 }
23 }
24}
25
26impl<'a> Iterator for Iter<'a> {
27 type Item = (&'a str, &'a str);
28
29 fn next(&mut self) -> Option<<Self as Iterator>::Item> {
30 unsafe {
31 let empty: CString = CString::new("").unwrap();
32 let entry = av_dict_get(self.ptr, empty.as_ptr(), self.cur, AV_DICT_IGNORE_SUFFIX);
33
34 if !entry.is_null() {
35 let key: &str = from_utf8_unchecked(CStr::from_ptr((*entry).key).to_bytes());
36 let val: &str = from_utf8_unchecked(CStr::from_ptr((*entry).value).to_bytes());
37
38 self.cur = entry;
39
40 Some((key, val))
41 } else {
42 None
43 }
44 }
45 }
46}
47