macro_rules! hn_once {
($($clmv:ident,)* |_| $body:expr) => { ... };
($($clmv:ident,)* |$args:ident| $body:expr) => { ... };
($($clmv:ident,)* |$args:ident : & $Args:ty| $body:expr) => { ... };
}Expand description
Declare a clone-move event handler that is only called once.
The macro input is a closure with optional clone-move variables, internally it uses clmv! so
the input is the same syntax.
ยงExamples
The example captures data by move and then destroys it in the first call, this cannot be done using hn! because
the data needs to be available for all event calls. In this case the closure is only called once, subsequent events
are ignored by the handler.
let data = vec![1, 2, 3];
on_click = hn_once!(|_| {
for i in data {
print!("{i}, ");
}
});