1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use super::{Block, Tag};
use crate::Content;
use crate::encoding::Encoder;
#[derive(Debug, PartialEq, Eq)]
pub struct Section<'section> {
blocks: &'section [Block<'section>],
}
impl<'section> Section<'section> {
pub(crate) const fn new(blocks: &'section [Block<'section>]) -> Self {
Self {
blocks,
}
}
pub fn render_once<C, E>(&self, content: &C, encoder: &mut E) -> Result<(), E::Error>
where
C: Content,
E: Encoder,
{
let mut index = 0;
while let Some(block) = self.blocks.get(index) {
index += 1;
encoder.write_unescaped(block.html)?;
match block.tag {
Tag::Escaped => content.render_field_escaped(block.hash, block.name, encoder)?,
Tag::Unescaped => content.render_field_unescaped(block.hash, block.name, encoder)?,
Tag::Section(count) => {
content.render_field_section(block.hash, block.name, Section::new(&self.blocks[index..index + count]), encoder)?;
index += count;
},
Tag::Inverse(count) => {
content.render_field_inverse(block.hash, block.name, Section::new(&self.blocks[index..index + count]), encoder)?;
index += count;
},
Tag::Closing |
Tag::Comment => {},
}
}
Ok(())
}
}