From c1e907ad703fc88de60e3f7c99fdc1e53658ff93 Mon Sep 17 00:00:00 2001 From: lummax Date: Thu, 3 Sep 2015 11:14:46 +0200 Subject: [PATCH] util/dictionary: implement `get()` --- src/util/dictionary.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/dictionary.rs b/src/util/dictionary.rs index 646a7be..d34baa0 100644 --- a/src/util/dictionary.rs +++ b/src/util/dictionary.rs @@ -54,6 +54,20 @@ impl<'a> Dictionary<'a> { } } + pub fn get(&'a self, key: &str) -> Option<&'a str> { + unsafe { + let key = CString::new(key).unwrap(); + let entry = av_dict_get(self.as_ptr(), key.as_ptr(), ptr::null_mut(), 0); + + if entry.is_null() { + None + } + else { + Some(from_utf8_unchecked(CStr::from_ptr((*entry).value).to_bytes())) + } + } + } + pub fn iter(&self) -> DictionaryIter { unsafe { DictionaryIter::new(self.as_ptr())