pub enum TemplateShape {
Unit,
Scalar {
child: u32,
},
Record,
Tuple,
}Expand description
What a lowered template’s parts add up to (§7.3).
§7.3: named captures produce an anonymous record; anonymous captures produce
a scalar when there is one and a tuple when there are several. A template
with no captures matches literally and produces Unit.
Stated here, next to the parts it classifies, and asked rather than
re-derived (ADR-092). The interpreter assembles a template’s value
(walk_template) and tags a collection built from it
(template_result_descriptor) through this one function, because answering
the question separately is how the two drift: a tag that says Unit for the
tuple shape makes read lines(`{int},{int}`) print [Unit, Unit] and
compare unequal to an identical Vec built with push, while
praxis check types it Vec[(Int, Int)] throughout.
There is no PlanNode::Tuple, and that is not an omission. A variant
carrying only child indices cannot represent a multi-capture template,
because the template’s separators are TemplatePartNode::Literals between
the captures — `{int},{int}` would lose its comma. Widening it to hold
the literals makes it PlanNode::Template again. So the tuple shape is a
property of a Template’s parts, which is what this type reads, and the
state “a tuple node” is unnameable rather than merely unreachable.
synthesize::template_type answers the same question for the type, over
AST TemplateParts rather than lowered ones. Keep the two in step.
Variants§
Unit
No captures: the template matches literally and produces Unit.
Scalar
One anonymous capture: the result is that capture’s value, and its type
is the child parser’s own result type. child is the child node index.
Record
At least one named capture: an anonymous record, one field per capture. Mixing named and anonymous captures in one template is rejected before lowering (§7.3), so “any named” and “all named” are the same set here.
Tuple
Two or more captures, none named: a tuple, one element per capture in source order.
Implementations§
Source§impl TemplateShape
impl TemplateShape
Sourcepub fn of(parts: &[TemplatePartNode]) -> TemplateShape
pub fn of(parts: &[TemplatePartNode]) -> TemplateShape
Classify a lowered template’s parts.
Trait Implementations§
Source§impl Clone for TemplateShape
impl Clone for TemplateShape
Source§fn clone(&self) -> TemplateShape
fn clone(&self) -> TemplateShape
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more