util/dictionary: implement set()

This commit is contained in:
lummax 2015-09-03 11:14:35 +02:00 committed by meh
parent 2a3a4e6169
commit 9cc2d28223

View File

@ -40,6 +40,20 @@ impl<'a> Dictionary<'a> {
Dictionary { ptr: ptr::null_mut(), _own: true, _marker: PhantomData } Dictionary { ptr: ptr::null_mut(), _own: true, _marker: PhantomData }
} }
pub fn set(&mut self, key: &str, value: &str) {
unsafe {
let key = CString::new(key).unwrap();
let value = CString::new(value).unwrap();
let mut ptr = self.as_mut_ptr();
if av_dict_set(&mut ptr, key.as_ptr(), value.as_ptr(), 0) < 0 {
panic!("out of memory");
}
self.ptr = ptr;
}
}
pub fn iter(&self) -> DictionaryIter { pub fn iter(&self) -> DictionaryIter {
unsafe { unsafe {
DictionaryIter::new(self.as_ptr()) DictionaryIter::new(self.as_ptr())