diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/askama/src/helpers.rs | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/askama/src/helpers.rs')
-rw-r--r-- | vendor/askama/src/helpers.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/askama/src/helpers.rs b/vendor/askama/src/helpers.rs new file mode 100644 index 000000000..79a1ada20 --- /dev/null +++ b/vendor/askama/src/helpers.rs @@ -0,0 +1,48 @@ +use std::iter::{Enumerate, Peekable}; + +pub struct TemplateLoop<I> +where + I: Iterator, +{ + iter: Peekable<Enumerate<I>>, +} + +impl<I> TemplateLoop<I> +where + I: Iterator, +{ + #[inline] + pub fn new(iter: I) -> Self { + TemplateLoop { + iter: iter.enumerate().peekable(), + } + } +} + +impl<I> Iterator for TemplateLoop<I> +where + I: Iterator, +{ + type Item = (<I as Iterator>::Item, LoopItem); + + #[inline] + fn next(&mut self) -> Option<(<I as Iterator>::Item, LoopItem)> { + self.iter.next().map(|(index, item)| { + ( + item, + LoopItem { + index, + first: index == 0, + last: self.iter.peek().is_none(), + }, + ) + }) + } +} + +#[derive(Copy, Clone)] +pub struct LoopItem { + pub index: usize, + pub first: bool, + pub last: bool, +} |