From e18f86f7c0ef60a8b06af3948c6101d3566d6ad5 Mon Sep 17 00:00:00 2001 From: meh Date: Sat, 20 Mar 2021 23:02:36 +0100 Subject: [PATCH] feat(dictionary): make methods accessible from an Owned dictionary --- src/util/dictionary/mutable.rs | 4 +++- src/util/dictionary/owned.rs | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/util/dictionary/mutable.rs b/src/util/dictionary/mutable.rs index 25ce2b0..7839daa 100644 --- a/src/util/dictionary/mutable.rs +++ b/src/util/dictionary/mutable.rs @@ -25,7 +25,7 @@ impl<'a> Ref<'a> { } impl<'a> Ref<'a> { - pub fn set(&mut self, key: &str, value: &str) { + pub fn set(&mut self, key: &str, value: &str) -> &mut Self { unsafe { let key = CString::new(key).unwrap(); let value = CString::new(value).unwrap(); @@ -38,6 +38,8 @@ impl<'a> Ref<'a> { self.ptr = ptr; self.imm = immutable::Ref::wrap(ptr); } + + self } } diff --git a/src/util/dictionary/owned.rs b/src/util/dictionary/owned.rs index d15eaa8..f2aed24 100644 --- a/src/util/dictionary/owned.rs +++ b/src/util/dictionary/owned.rs @@ -24,11 +24,11 @@ impl Owned { result } - pub fn as_ptr(&self) -> *const AVDictionary { + pub unsafe fn as_ptr(&self) -> *const AVDictionary { self.ptr } - pub fn as_mut_ptr(&mut self) -> *mut AVDictionary { + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVDictionary { self.ptr } } @@ -47,6 +47,15 @@ impl Owned { pub fn as_mut(&self) -> mutable::Ref { unsafe { mutable::Ref::wrap(self.ptr) } } + + pub fn iter(&self) -> Iter<'_> { + unsafe { Iter::new(self.as_ptr()) } + } + + pub fn set(&mut self, key: &str, value: &str) -> &mut Self { + self.as_mut().set(key, value); + self + } } impl<'a> FromIterator<(&'a str, &'a str)> for Owned {