Skip to main content

substitute_context

Function substitute_context 

Source
pub fn substitute_context(
    template: &str,
    context: &HashMap<String, Value>,
) -> String
Expand description

Substitute {key} placeholders in a template string with values from context.

Value conversion rules:

  • String -> raw string (no quotes)
  • Number -> number as string
  • Bool -> "true" / "false"
  • Null -> "null"
  • Array / Object -> JSON-serialized string

Unmatched placeholders are left as-is.

Warning: Do NOT use this for SQL queries (SQL injection risk) or for substitution into serialized JSON (corruption risk with special characters). Use substitute_context_bind_params for SQL and substitute_context_json for serialized JSON.