Skip to main content

interpolate_operands

Function interpolate_operands 

Source
pub fn interpolate_operands<F>(text: &str, lookup: F) -> Result<String, String>
where F: Fn(&str) -> Option<Value>,
Expand description

Interpolate an expression’s placeholders, reading each placeholder that is a whole operand as the value its name is bound to (comprehension_forms.md §3.1.5).

A placeholder is a whole operand when it stands outside a quoted string and no character of a larger token touches it: in f({size}, 1) and {n} + 1 it is one, and in x_{size}, {a}.{b} and "{size}" it is not. A whole operand whose name (composed from its leaves first, for {a_{b}}) is bound is written as a literal the language reads back as that value: a string is quoted, and every other value is written as it displays. Every other placeholder substitutes text, as interpolate_with_lookup does, and a whole operand whose name is not bound is left to that rule, so an unresolved name is reported the same way.