Macro zng::var::merge_var

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

Initializes a new Var 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

§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 BoxedVar<T> that is either an ArcMergeVar<T> or a ContextualizedVar<T, ArcMergeVar<T>>.

§Examples

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

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