From 620958d6840c49b430866f0787939815e5f38e39 Mon Sep 17 00:00:00 2001 From: lummax Date: Thu, 3 Sep 2015 11:15:22 +0200 Subject: [PATCH] util/dictionary: implement `Clone for Dictionary` --- src/util/dictionary.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/util/dictionary.rs b/src/util/dictionary.rs index d34baa0..69dc400 100644 --- a/src/util/dictionary.rs +++ b/src/util/dictionary.rs @@ -75,6 +75,32 @@ impl<'a> Dictionary<'a> { } } +impl<'a> Clone for Dictionary<'a> { + fn clone(&self) -> Self { + let mut dictionary = Dictionary::new(); + dictionary.clone_from(self); + + dictionary + } + + fn clone_from(&mut self, source: &Self) { + unsafe { + let mut ptr = self.as_mut_ptr(); + av_dict_copy(&mut ptr, source.as_ptr(), 0); + self.ptr = ptr; + } + } +} + +impl<'a> IntoIterator for &'a Dictionary<'a> { + type Item = (&'a str, &'a str); + type IntoIter = DictionaryIter<'a>; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + impl<'a> Drop for Dictionary<'a> { fn drop(&mut self) { unsafe { @@ -125,12 +151,3 @@ impl<'a> Iterator for DictionaryIter<'a> { } } } - -impl<'a> IntoIterator for &'a Dictionary<'a> { - type Item = (&'a str, &'a str); - type IntoIter = DictionaryIter<'a>; - - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -}