summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-08 22:01:30 -0400
committerpommicket <pommicket@gmail.com>2025-09-08 22:01:30 -0400
commite3a4ef53a75bc10129010cf18fb7ce68a6acbf2a (patch)
tree6d7aeabe48ca02f0f83ac6a59178f9b7ca6aadac /src/lib.rs
parentaf57af207e5106a47e50ae1ca6de7f746cfe8da6 (diff)
Add iter(), more tests
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())
+ }
+}