Template

Struct Template 

Source
pub struct Template { /* private fields */ }
Expand description

A field-value template.

Implementations§

Source§

impl Template

Source

pub fn parse2(input: TokenStream) -> Result<Self, Error>

Parse a template from a TokenStream.

The TokenStream is typically all the tokens given to a macro.

Source

pub fn before_literal_field_values<'a>( &'a self, ) -> impl Iterator<Item = &'a FieldValue>

Field-values that appear before the template string literal.

Source

pub fn literal_field_values<'a>( &'a self, ) -> impl Iterator<Item = &'a FieldValue>

Field-values that appear within the template string literal.

This is a simple alternative to Template::visit_literal that iterates over the field-value holes.

Source

pub fn has_literal(&self) -> bool

Whether the template contains a literal.

Source

pub fn after_literal_field_values<'a>( &'a self, ) -> impl Iterator<Item = &'a FieldValue>

Field-values that appear after the template string literal.

Source

pub fn visit_literal(&self, visitor: impl LiteralVisitor)

Visit the parts of the string literal part of the template.

Each fragment of text and field-value hole will be visited in sequence.

Given a template string like:

Some text and a {hole} and some {more}.

the visitor will be called with the following inputs:

  1. visit_text("Some text and a ")
  2. visit_hole("hole")
  3. visit_text(" and some ")
  4. visit_hole("more")
  5. visit_text(".")

If the template doesn’t contain a literal then the visitor won’t be called.

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