Keats / tera2

37 stars 5 forks source link

Add context! macro to reduce boilerplate when building Contexts #24

Closed GandelXIV closed 9 months ago

GandelXIV commented 9 months ago

This macro greatly simplifies building Contexts, as you just pass it key-value pairs and inserts them for you.

Example:

use tera::context;
let ctx = context! {
    name => "Brian",
    age => &24
};

Expands to:

let ctx = {
    let mut context = Context::new();
    context.insert("name", "Brian");
    context.insert("age", &24);
    context
};