merge_var

Macro merge_var 

Source
macro_rules! merge_var {
    ($($tt:tt)+) => { ... };
}
Expand description

Initializes a new Var<T> with value made by merging multiple other variables.

§Arguments

All arguments are separated by comma like a function call.

  • var0..N: A list of vars, minimal 2.
  • merge: A new closure that produces a new value from references to all variable values. FnMut(&var0_T, ..) -> merge_T

Note that the vars can be of any of Var<T>, ContextVar<T> or ResponseVar<T>, that is, already constructed var types, not all types that convert into var.

§Contextualized

The merge var is contextualized when needed, meaning if any input is contextual at the moment the var is created it is also contextual. The full output type of this macro is a Var<O>, the O type is defined by the output of the merge closure.

§Examples

let var0: Var<Txt> = var_from("Hello");
let var1: Var<Txt> = var_from("World");

let greeting_text = Text!(merge_var!(var0, var1, |a, b| formatx!("{a} {b}!")));