diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-25 15:50:13 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-25 15:50:13 +0200 |
| commit | 09aabc3a21e403e0b09a6d6ba517e34a303b217c (patch) | |
| tree | 590a26bdfe3c5c3c1a48a0271ba54ee3b076a791 /src/model/collapse.rs | |
| parent | 649c101f07f6de4791dc9b6091dff4a85112a15c (diff) | |
Public style entry enum
Diffstat (limited to 'src/model/collapse.rs')
| -rw-r--r-- | src/model/collapse.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/model/collapse.rs b/src/model/collapse.rs index 5e7a25f8..18cfae8b 100644 --- a/src/model/collapse.rs +++ b/src/model/collapse.rs @@ -2,8 +2,12 @@ use super::{StyleChain, StyleVec, StyleVecBuilder}; /// A wrapper around a [`StyleVecBuilder`] that allows to collapse items. pub struct CollapsingBuilder<'a, T> { + /// The internal builder. builder: StyleVecBuilder<'a, T>, + /// Staged weak and ignorant items that we can't yet commit to the builder. + /// The option is `Some(_)` for weak items and `None` for ignorant items. staged: Vec<(T, StyleChain<'a>, Option<u8>)>, + /// What the last non-ignorant item was. last: Last, } @@ -51,14 +55,14 @@ impl<'a, T> CollapsingBuilder<'a, T> { /// Forces nearby weak items to collapse. pub fn destructive(&mut self, item: T, styles: StyleChain<'a>) { self.flush(false); - self.push(item, styles); + self.builder.push(item, styles); self.last = Last::Destructive; } /// Allows nearby weak items to exist. pub fn supportive(&mut self, item: T, styles: StyleChain<'a>) { self.flush(true); - self.push(item, styles); + self.builder.push(item, styles); self.last = Last::Supportive; } @@ -78,7 +82,8 @@ impl<'a, T> CollapsingBuilder<'a, T> { self.builder.finish() } - /// Push the staged items, filtering out weak items if `supportive` is false. + /// Push the staged items, filtering out weak items if `supportive` is + /// false. fn flush(&mut self, supportive: bool) { for (item, styles, strength) in self.staged.drain(..) { if supportive || strength.is_none() { @@ -86,11 +91,6 @@ impl<'a, T> CollapsingBuilder<'a, T> { } } } - - /// Push a new item into the style vector. - fn push(&mut self, item: T, styles: StyleChain<'a>) { - self.builder.push(item, styles); - } } impl<'a, T> Default for CollapsingBuilder<'a, T> { |
