diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-26 00:29:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-26 00:29:37 +0200 |
| commit | 7aa3d2c2d6c60c9d4696bf2fb91982a5be64f9b0 (patch) | |
| tree | 3fbbebbb3540294fada6fc356cd12c31825dcff8 /src/layout/mod.rs | |
| parent | 56cbf96fe2b3b82d34b2e69a49bcb7b0c0267f6a (diff) | |
No more excessive region cloning
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 22e6e8c8..0f88d150 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -140,14 +140,21 @@ impl Regions { self.backlog.is_empty() && self.last.map_or(true, |size| self.current == size) } + /// An iterator that returns pairs of `(current, base)` that are equivalent + /// to what would be produced by calling [`next()`](Self::next) repeatedly + /// until all regions are exhausted. + pub fn iter(&self) -> impl Iterator<Item = (Size, Size)> + '_ { + let first = std::iter::once((self.current, self.base)); + let backlog = self.backlog.iter().rev(); + let last = self.last.iter().cycle(); + first.chain(backlog.chain(last).map(|&s| (s, s))) + } + /// Advance to the next region if there is any. - pub fn next(&mut self) -> bool { + pub fn next(&mut self) { if let Some(size) = self.backlog.pop().or(self.last) { self.current = size; self.base = size; - true - } else { - false } } |
