TemplateContextBuilder

Struct TemplateContextBuilder 

Source
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

Source

pub fn new() -> Self

Start building a new template context

Source

pub fn with_defaults() -> Self

Start with default PRD v1.0 variables

Source

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 name
  • value - Variable value (string, number, bool, array, or object)
Source

pub fn vars<K, V, I>(self, vars: I) -> Self
where K: Into<String>, V: Into<Value>, I: IntoIterator<Item = (K, V)>,

Add multiple variables at once

Source

pub fn matrix<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self

Add a matrix parameter

§Arguments
  • key - Matrix parameter name
  • value - Parameter value
Source

pub fn matrix_params<K, V, I>(self, params: I) -> Self
where K: Into<String>, V: Into<Value>, I: IntoIterator<Item = (K, V)>,

Add multiple matrix parameters

Source

pub fn otel<K: Into<String>, V: Into<Value>>(self, key: K, value: V) -> Self

Add an OpenTelemetry configuration value

§Arguments
  • key - OTEL configuration key
  • value - Configuration value
Source

pub fn otel_config<K, V, I>(self, config: I) -> Self
where K: Into<String>, V: Into<Value>, I: IntoIterator<Item = (K, V)>,

Add multiple OTEL configuration values

Source

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

Source

pub fn merge_vars(self, user_vars: HashMap<String, Value>) -> Self

Merge user-provided variables (highest precedence)

Source

pub fn load_vars_from_file<P: AsRef<Path>>(self, path: P) -> Result<Self>

Load variables from a JSON file

§Arguments
  • path - Path to JSON file containing variables
Source

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
Source

pub fn build(self) -> TemplateContext

Build the final template context

Trait Implementations§

Source§

impl Default for TemplateContextBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V