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

@ -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

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`].
///