pub struct VariableSubstitutor;Expand description
Variable substitution engine
Provides methods for substituting variables in templates using event context. Supports:
- Simple variable substitution:
{{variable_name}} - Nested path substitution:
{{metadata.size}} - Literal text with variables:
"path/{{file_path}}/subdir" - Error handling for missing variables
Implementations§
Source§impl VariableSubstitutor
impl VariableSubstitutor
Sourcepub fn substitute(template: &str, context: &EventContext) -> Result<String>
pub fn substitute(template: &str, context: &EventContext) -> Result<String>
Substitute variables in a template string
Replaces all {{variable_name}} placeholders with values from the event context.
Supports nested paths like {{metadata.size}}.
§Arguments
template- Template string with placeholderscontext- Event context containing variables
§Returns
Substituted string or error if variables are missing
§Examples
ⓘ
let context = EventContext {
data: json!({"file_path": "/path/to/file.rs"}),
metadata: json!({}),
};
let result = VariableSubstitutor::substitute("File: {{file_path}}", &context)?;
assert_eq!(result, "File: /path/to/file.rs");Sourcepub fn substitute_json(value: &Value, context: &EventContext) -> Result<Value>
pub fn substitute_json(value: &Value, context: &EventContext) -> Result<Value>
Substitute variables in a JSON value
If the value is a string, performs variable substitution. If the value is an object or array, recursively substitutes in all string values. Other types are returned unchanged.
§Arguments
value- JSON value to substitutecontext- Event context containing variables
§Returns
Substituted JSON value or error if variables are missing
Auto Trait Implementations§
impl Freeze for VariableSubstitutor
impl RefUnwindSafe for VariableSubstitutor
impl Send for VariableSubstitutor
impl Sync for VariableSubstitutor
impl Unpin for VariableSubstitutor
impl UnwindSafe for VariableSubstitutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more