Hi,
I want my combobox to return a 2 strings, so I know which combo on the ui was used (I have a lot of them).
So when creating the combobox, I try and have the closure capture a string which I can return from on_selected, similar to below,
for i in &v.state {
let c = combo_box(&i.combo_state, "", Some(&i.value),move |x| Message::ComboSelected(v.name.clone(), x));
site_container = site_container.push(c);
}
I get an error that goes:
for v in s {
| ^
| |
| `state` escapes the function body here
| argument requires that `'1` must outlive `'static`
If I try a similar thing with text(), it works, similar to below:
for (k,v) in &i.codes_map {
let t = text_input(k, v).on_input(move |s| Message::NightCodeChanged(n,n2,k.to_string(),s));
items_row = items_row.push(t);
}
If I look at the docs for combobox on_selected versus textinput’s on_input, I see the following:
combobox new function has:
on_selected: impl Fn(T) → Message + 'static,
And textinput on_input has:
I’m guessing the 'static is the issue on combobox? Why would combobox need 'static lifetimes and how can I get around this I wonder?
If I try and move the clone() out of the closure with below:
for i in &v.state {
let n = v.name.clone();
let c = combo_box(&i.combo_state, "", Some(&i.value),
move |x| Message::ComboSelected(n, x));
site_container = site_container.push(c);
}
The error I then get looks like:
292 | let n = v.name.clone();
| - captured outer variable
293 | let c = combo_box(&i.combo_state, "", Some(&i.value),
294 | move |x| Message::ComboSelected2(0, 0, n, x));
| -------- captured by this `Fn` closure ^ move occurs because `n` has type `std::string::String`, which does not implement the `Copy` trait
Any advice or suggestions would be appreciated.
Thanks