summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-04-20 11:02:27 +0200
committerNadrieril2019-04-20 11:02:27 +0200
commita60cf58e5f0cc2f638b788720f9a12cabfdbe3f2 (patch)
tree941152962947608698029598c52696265be6e3e7 /dhall_core
parent151a14dad84d4d0f02045ea9b69d63e2cb9fe17e (diff)
Text literals
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/text.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/dhall_core/src/text.rs b/dhall_core/src/text.rs
index 0cfbd7b..e886659 100644
--- a/dhall_core/src/text.rs
+++ b/dhall_core/src/text.rs
@@ -72,9 +72,21 @@ impl<SubExpr> InterpolatedText<SubExpr> {
}),
)
}
+
+ pub fn into_iter(
+ self,
+ ) -> impl Iterator<Item = InterpolatedTextContents<SubExpr>> {
+ use std::iter::once;
+ once(InterpolatedTextContents::Text(self.head)).chain(
+ self.tail.into_iter().flat_map(|(e, s)| {
+ once(InterpolatedTextContents::Expr(e))
+ .chain(once(InterpolatedTextContents::Text(s)))
+ }),
+ )
+ }
}
-impl<'a, SubExpr: Clone + 'a> FromIterator<InterpolatedTextContents<SubExpr>>
+impl<'a, SubExpr: 'a> FromIterator<InterpolatedTextContents<SubExpr>>
for InterpolatedText<SubExpr>
{
fn from_iter<T>(iter: T) -> Self
@@ -90,7 +102,7 @@ impl<'a, SubExpr: Clone + 'a> FromIterator<InterpolatedTextContents<SubExpr>>
match x {
InterpolatedTextContents::Text(s) => crnt_str.push_str(&s),
InterpolatedTextContents::Expr(e) => {
- res.tail.push((e.clone(), "".to_owned()));
+ res.tail.push((e, "".to_owned()));
crnt_str = &mut res.tail.last_mut().unwrap().1;
}
}