summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4a12e5b..56ecb61 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -689,7 +689,7 @@ impl Configuration {
}
}
- /// Get the list of all “direct keys” in this configuration.
+ /// Get all “direct keys” in this configuration.
///
/// More specifically, this returns an iterator of all unique
/// first components of keys in `self`.
@@ -712,6 +712,15 @@ impl Configuration {
})
}
+ /// Get all defined keys in this configuration, including nested ones,
+ /// and their values.
+ ///
+ /// The order of items returned is arbitrary and may change
+ /// in future versions without notice.
+ pub fn iter(&self) -> ConfigurationIter {
+ self.into_iter()
+ }
+
/// Get the list of all “direct children” of `key` in this configuration.
///
/// More specifically, this returns an iterator of all unique
@@ -893,3 +902,24 @@ impl Configuration {
todo!()
}
}
+
+/// Opaque type returned by [`<&Configuration>::into_iter`].
+#[derive(Clone, Debug)]
+pub struct ConfigurationIter<'a>(core::slice::Iter<'a, (Box<str>, Value)>);
+
+impl<'a> Iterator for ConfigurationIter<'a> {
+ type Item = (&'a str, &'a str);
+ fn next(&mut self) -> Option<Self::Item> {
+ let (key, val) = self.0.next()?;
+ Some((key, val.value.as_ref()))
+ }
+}
+
+impl<'a> IntoIterator for &'a Configuration {
+ type IntoIter = ConfigurationIter<'a>;
+ type Item = (&'a str, &'a str);
+ /// See [`Configuration::iter`].
+ fn into_iter(self) -> Self::IntoIter {
+ ConfigurationIter(self.items.iter())
+ }
+}