util/dictionary: add Dictionary

This commit is contained in:
meh 2015-05-12 03:12:55 +02:00
parent 4e79ee9ae9
commit 1c2b78a3f2
3 changed files with 38 additions and 0 deletions

View File

@ -7,3 +7,4 @@ extern crate ffmpeg_sys as ffi;
pub mod util;
pub use util::error::Error;
pub use util::dictionary::Dictionary;

36
src/util/dictionary.rs Normal file
View File

@ -0,0 +1,36 @@
use std::marker::PhantomData;
use std::ptr;
use ffi::*;
pub struct Dictionary<'a> {
pub ptr: *mut AVDictionary,
own: bool,
_marker: PhantomData<&'a i32>,
}
impl<'a> Dictionary<'a> {
pub fn new() -> Self {
Dictionary { ptr: ptr::null_mut(), own: true, _marker: PhantomData }
}
pub fn wrap(ptr: *mut AVDictionary) -> Self {
Dictionary { ptr: ptr, own: false, _marker: PhantomData }
}
pub fn take(&mut self) -> *mut AVDictionary {
self.own = false;
self.ptr
}
}
impl<'a> Drop for Dictionary<'a> {
fn drop(&mut self) {
unsafe {
if self.own && self.ptr != ptr::null_mut() {
av_dict_free(&mut self.ptr);
}
}
}
}

View File

@ -1,3 +1,4 @@
pub mod dictionary;
pub mod error;
use std::ffi::CStr;