Skip to main content

TemplateShape

Enum TemplateShape 

Source
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.

Fields

§child: u32
§

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

Source

pub fn of(parts: &[TemplatePartNode]) -> TemplateShape

Classify a lowered template’s parts.

Trait Implementations§

Source§

impl Clone for TemplateShape

Source§

fn clone(&self) -> TemplateShape

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TemplateShape

Source§

impl Debug for TemplateShape

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TemplateShape

Source§

impl PartialEq for TemplateShape

Source§

fn eq(&self, other: &TemplateShape) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TemplateShape

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.