Skip to main content

parse_template

Function parse_template 

Source
pub fn parse_template(source: &str) -> Result<StringTemplate, ParseError>
Expand description

Parses a single quoted string literal (e.g. "target/{profile}/app", quotes included) into a StringTemplate, treating source as though it were the whole world: spans in the result are 0-based byte offsets into source itself. Use [parse_template_at] when the literal is embedded in a larger file and spans must land in that original source.

This is a real public entry point, not just a test helper, so it holds itself to a public API’s input contract: source is lexed first (the same way parser::parse lexes a whole file), and anything other than exactly one string literal followed by end of input — an empty string, unquoted text, a bad escape, an unterminated literal, trailing content, and so on — is rejected with a ParseError rather than panicking or silently misparsing. That validation is what lets [parse_template_at] below assume its span always names a string the lexer already accepted.