[librsvg: 47/95] PropertyBag: Add an iter_cstr() that outputs &CStr, instead of &str
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 47/95] PropertyBag: Add an iter_cstr() that outputs &CStr, instead of &str
- Date: Thu, 22 Feb 2018 03:17:05 +0000 (UTC)
commit b6334ccb01e079a1406d9b9f3f19efd794581103
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Feb 20 18:39:29 2018 -0600
PropertyBag: Add an iter_cstr() that outputs &CStr, instead of &str
rust/src/property_bag.rs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
---
diff --git a/rust/src/property_bag.rs b/rust/src/property_bag.rs
index 2c99ed3c..c8d462c8 100644
--- a/rust/src/property_bag.rs
+++ b/rust/src/property_bag.rs
@@ -12,6 +12,8 @@ pub struct OwnedPropertyBag(HashMap<CString, CString>);
pub struct PropertyBagIter<'a>(hash_map::Iter<'a, &'a CStr, &'a CStr>);
+pub struct PropertyBagCStrIter<'a>(hash_map::Iter<'a, &'a CStr, &'a CStr>);
+
impl<'a> PropertyBag<'a> {
pub unsafe fn new_from_key_value_pairs(pairs: *const *const libc::c_char) -> PropertyBag<'a> {
let mut map = HashMap::new();
@@ -87,6 +89,10 @@ impl<'a> PropertyBag<'a> {
pub fn iter(&self) -> PropertyBagIter {
PropertyBagIter(self.0.iter())
}
+
+ pub fn cstr_iter(&self) -> PropertyBagCStrIter {
+ PropertyBagCStrIter(self.0.iter())
+ }
}
impl<'a> Iterator for PropertyBagIter<'a> {
@@ -97,6 +103,14 @@ impl<'a> Iterator for PropertyBagIter<'a> {
}
}
+impl<'a> Iterator for PropertyBagCStrIter<'a> {
+ type Item = (&'a CStr, &'a CStr);
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.0.next().map(|(k, v)| (*k, *v))
+ }
+}
+
#[no_mangle]
pub extern fn rsvg_property_bag_new<'a>(atts: *const *const libc::c_char) -> *const PropertyBag<'a> {
let pbag = unsafe { PropertyBag::new_from_key_value_pairs(atts) };
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]