macro_rules! clone {
($($x:ident),+ => $y:expr) => { ... };
}Expand description
Used as a shorthand syntax for calling .clone() when parsing variables into functions. Due to
'static requirements of many of the web apis move and clone are frequently required.
clone!(clone_item_1, clone_item_2, clone_item_3 => { expression using the clones })Where the clone_item_x shadow existing variable names.
So instead of writing:
let text = Mutable::new("text");
let other_text = Mutable::new("other text");
html!("div", {
.event({
let text = text.clone();
let other_text = text.clone();
move |_: events::Click| {
text.set("clicked");
other_text.set("clicked")
}})
.event({
let other_text = other_text.clone();
move |_: events::Focus| {
text.set("focused");
other_text.set("focused")
}})
.text_signal(other_text.signal_cloned())
});clone! can make a cleaner syntax sharing the same variable names:
let text = Mutable::new("text");
let other_text = Mutable::new("other text");
html!("div", {
.event(clone!(text, other_text => move |_: events::Click| {
text.set("clicked");
other_text.set("clicked")
}))
.event(clone!(other_text => move |_: events::Focus| {
text.set("focused");
other_text.set("focused")
}))
.text_signal(other_text.signal_cloned())
});