From 7b8322b6e131b7edaa1bade7b37cdd49017c1cb8 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 18 Feb 2021 23:35:22 +0800 Subject: [PATCH] Scope implements IntoIterator. --- RELEASES.md | 4 +++- src/scope.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index a3ee4317..bd1b91fb 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -12,8 +12,10 @@ Bug fixes Enhancements ------------ +* Comparisons between `FLOAT`/[`Decimal`](https://crates.io/crates/rust_decimal) and `INT` are now built in. * Error position in `eval` statements is now wrapped in an `EvalAltResult::ErrorInFunctionCall`. * `Position` now implements `Add` and `AddAssign`. +* `Scope` now implements `IntoIterator`. Version 0.19.12 @@ -54,7 +56,7 @@ Enhancements * Functions resolution cache is used in more cases, making repeated function calls faster. * Added `atan(x, y)` and `hypot(x, y)` to `BasicMathPackage`. -* Added standard arithmetic operators between `FLOAT` and `INT`. +* Added standard arithmetic operators between `FLOAT`/[`Decimal`](https://crates.io/crates/rust_decimal) and `INT`. Version 0.19.11 diff --git a/src/scope.rs b/src/scope.rs index 77c74e9e..4adda3e1 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -64,6 +64,20 @@ impl Default for Scope<'_> { } } +impl<'a> IntoIterator for Scope<'a> { + type Item = (Cow<'a, str>, Dynamic); + type IntoIter = Box + '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`]. ///