Scope implements IntoIterator.

This commit is contained in:
Stephen Chung
2021-02-18 23:35:22 +08:00
parent 61d7356e08
commit 7b8322b6e1
2 changed files with 17 additions and 1 deletions

View File

@@ -64,6 +64,20 @@ impl Default for Scope<'_> {
}
}
impl<'a> IntoIterator for Scope<'a> {
type Item = (Cow<'a, str>, Dynamic);
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
fn into_iter(self) -> Self::IntoIter {
Box::new(
self.values
.into_iter()
.zip(self.names.into_iter())
.map(|(value, (name, _))| (name, value)),
)
}
}
impl<'a> Scope<'a> {
/// Create a new [`Scope`].
///