bind

Macro bind 

Source
bind!() { /* proc-macro */ }
Expand description

Allows to conveniently clone values into closure.

use vertigo::{bind, dom, Value};

let count = Value::new(0);

let increment = bind!(count, |_| {
    count.change(|value| {
        *value += 1;
    });
});

dom! {
    <div>
        <p>"Counter: " { count }</p>
        <button on_click={increment}>"+"</button>
    </div>
};

Binding complex names results in last part being accessible inside:

use vertigo::bind;

struct Point {
    pub x: i32,
    pub y: i32,
}

let point = Point { x: 1, y: 2 };

let callback = bind!(point.x, point.y, || {
    println!("Point: ({x}, {y})");
});