Skip to main content

TemplatePart

Enum TemplatePart 

Source
pub enum TemplatePart {
    Literal {
        text: String,
        ws: WsPolicy,
        span: Span,
    },
    Capture {
        name: Option<CaptureName>,
        parser: Box<ParserAst>,
        span: Span,
        name_span: Option<Span>,
    },
}
Expand description

One part of a backtick template (§7.9 TemplatePart).

Every part carries its own source span, for the same reason every ParserAst node does (§7.10, ADR-078): the editor has to colour the capture name differently from the capture type (§19.11 criterion 4), and the only alternative to recording the extent where the scanner already knows it is a second scanner in the language server re-deriving it — the failure ADR-098 exists to prevent. Spans are interior-relative until shift_part_spans rebases them onto the file, exactly like the spans on the parser nodes underneath.

Variants§

§

Literal

A literal run: the raw matched bytes plus the whitespace policy.

span covers the source the run was decoded from, which is not the same length as text: \` is two source bytes and one character, and a policy part decoded from \s+ has an empty text and a two-byte span.

Fields

§text: String
§span: Span
§

Capture

A capture {name? : parser}. name is None for anonymous captures.

parser is the capture’s own parser expression, parsed from its own body (ADR-072), so captures in one template do not share a kind.

span covers the whole capture including both braces; name_span covers the name as trimmed ({ n :int} names n, not " n "), and is None exactly when name is. The capture’s type needs no span here: it is parser.span().

Fields

§parser: Box<ParserAst>
§span: Span
§name_span: Option<Span>

Implementations§

Source§

impl TemplatePart

Source

pub fn span(&self) -> Span

The part’s source span.

Trait Implementations§

Source§

impl Clone for TemplatePart

Source§

fn clone(&self) -> TemplatePart

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 Debug for TemplatePart

Source§

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

Formats the value using the given formatter. Read more

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