util/dictionary: add Dictionary
This commit is contained in:
parent
4e79ee9ae9
commit
1c2b78a3f2
@ -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
36
src/util/dictionary.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod dictionary;
|
||||
pub mod error;
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user