ffmpeg_the_third/util/dictionary/
mutable.rs1use std::fmt;
2
3use super::Dictionary;
4use crate::ffi::*;
5use crate::{AsMutPtr, AsPtr};
6
7pub struct DictionaryMut<'d> {
8 ptr: &'d mut *mut AVDictionary,
9}
10
11impl<'d> DictionaryMut<'d> {
12 pub unsafe fn from_raw(ptr: &'d mut *mut AVDictionary) -> Self {
13 DictionaryMut { ptr }
14 }
15
16 pub fn replace_with(&mut self, new: Dictionary) {
17 unsafe { av_dict_free(self.ptr) };
18 *self.ptr = new.into_raw();
19 }
20
21 pub fn as_ptr(&self) -> *const AVDictionary {
22 *self.ptr
23 }
24
25 pub fn as_mut_ptr(&mut self) -> &mut *mut AVDictionary {
26 self.ptr
27 }
28
29 pub fn as_ref(&self) -> super::DictionaryRef<'d> {
30 unsafe { super::DictionaryRef::from_raw(self.as_ptr()) }
31 }
32}
33
34impl<'d> fmt::Debug for DictionaryMut<'d> {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 self.as_ref().fmt(f)
37 }
38}
39
40impl<'d> AsPtr<AVDictionary> for DictionaryMut<'d> {
41 fn as_ptr(&self) -> *const AVDictionary {
42 *self.ptr
43 }
44}
45
46impl<'d> AsMutPtr<*mut AVDictionary> for DictionaryMut<'d> {
47 fn as_mut_ptr(&mut self) -> *mut *mut AVDictionary {
48 self.ptr
49 }
50}