pub struct TemplateContextBuilder { /* private fields */ }Expand description
Fluent API for building template contexts
Provides method chaining for easy context construction:
use clnrm_template::TemplateContext;
let context = TemplateContext::builder()
.var("service_name", "my-service")
.var("environment", "production")
.matrix("browser", vec!["chrome", "firefox"])
.otel("endpoint", "http://localhost:4318")
.build();Implementations§
Source§impl TemplateContextBuilder
impl TemplateContextBuilder
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Start with default PRD v1.0 variables
Sourcepub fn var<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self
pub fn var<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self
Add a variable to the vars namespace
§Arguments
key- Variable namevalue- Variable value (string, number, bool, array, or object)
Sourcepub fn matrix_params<K, V, I>(self, params: I) -> Self
pub fn matrix_params<K, V, I>(self, params: I) -> Self
Add multiple matrix parameters
Sourcepub fn otel<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self
pub fn otel<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self
Add an OpenTelemetry configuration value
§Arguments
key- OTEL configuration keyvalue- Configuration value
Sourcepub fn otel_config<K, V, I>(self, config: I) -> Self
pub fn otel_config<K, V, I>(self, config: I) -> Self
Add multiple OTEL configuration values
Sourcepub fn var_with_env(self, key: &str, env_key: &str, default: &str) -> Self
pub fn var_with_env(self, key: &str, env_key: &str, default: &str) -> Self
Add variable with environment variable precedence
Sets variable with priority: existing vars → ENV → default
Sourcepub fn merge_vars(self, user_vars: HashMap<String, Value>) -> Self
pub fn merge_vars(self, user_vars: HashMap<String, Value>) -> Self
Merge user-provided variables (highest precedence)
Sourcepub fn load_vars_from_file<P: AsRef<Path>>(self, path: P) -> Result<Self>
pub fn load_vars_from_file<P: AsRef<Path>>(self, path: P) -> Result<Self>
Sourcepub fn load_matrix_from_file<P: AsRef<Path>>(self, path: P) -> Result<Self>
pub fn load_matrix_from_file<P: AsRef<Path>>(self, path: P) -> Result<Self>
Load matrix parameters from a TOML file
§Arguments
path- Path to TOML file containing matrix parameters
Sourcepub fn build(self) -> TemplateContext
pub fn build(self) -> TemplateContext
Build the final template context
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TemplateContextBuilder
impl RefUnwindSafe for TemplateContextBuilder
impl Send for TemplateContextBuilder
impl Sync for TemplateContextBuilder
impl Unpin for TemplateContextBuilder
impl UnwindSafe for TemplateContextBuilder
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