Skip to content

struct

TextTemplate

pub struct TextTemplate {
    pub parts: Vec<TextPart>,
}

A string with {path} interpolations.

Fields

parts

pub parts: Vec<TextPart>

The pieces, in order.

Methods

as_literal

pub fn as_literal(&self) -> Option<String>

A template that is just literal text. The text, when it's all literal (no interpolations).

literal

pub fn literal(s: &str) -> TextTemplate

A template of plain text, with no {…} parts.

parse

pub fn parse(raw: &str) -> Result<TextTemplate, String>

Parse raw string contents: process escapes (\" \\ \n \t \{ \}), treat {{ / }} as literal braces, and split out {path} interpolations.

is_static

pub fn is_static(&self) -> bool

True when there are no interpolations.

as_static

pub fn as_static(&self) -> Option<String>

The literal text, if the template has no interpolations.

references

pub fn references(&self) -> Vec<&Path>

Every interpolated plain path, in order (see [TextTemplate::collect_references] for expressions too).

collect_references

pub fn collect_references(&self, bound: &mut Vec<String>, out: &mut BTreeSet<String>)

Every name the interpolations read, bound names excluded.

render

pub fn render(&self, lookup: impl Fn(&Path) -> String) -> String

Produce the final string, resolving references with lookup. Expression interpolations print as written.

Trait implementations