pub struct Template { /* private fields */ }Expand description
A parsed template.
Implementations§
Source§impl Template
impl Template
Sourcepub fn parse(text: &str, kind: TemplateKind) -> Result<Self, TemplateError>
pub fn parse(text: &str, kind: TemplateKind) -> Result<Self, TemplateError>
Parses text for a template of kind (tokens).
Sourcepub fn expand<'v>(
&self,
value: impl Fn(Var) -> &'v [u8],
out: &mut Vec<u8>,
) -> usize
pub fn expand<'v>( &self, value: impl Fn(Var) -> &'v [u8], out: &mut Vec<u8>, ) -> usize
The expansion into out (cleared first): each variable’s value from
value (its raw bytes; a safe_ variable’s is safe of its plain
one’s, made as it is written), stopping at STOP bytes: what
follows decides nothing (check), so it is never made. No value
is copied whole: each is written up to the room left, so out never
holds more than STOP bytes, and a caller that gave it that
capacity allocates nothing here.
Gives how many of out’s last bytes are the start of a code point
the stop cut, one the whole expansion holds past the stop
(cut_tail): a text of the expansion drops them, where an invalid
byte is one code point (review round 3’s P3). The code point may
span pieces: the bytes before the stop are read joined with the
expansion’s next ones, of the piece cut and those after it (review
round 4’s A3).