Non-Static Lambdas in `on_submit` et al.
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 270
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 2
Description
The following is an attempt to get a formatted string from the user. `out` is the validator function and `and_then` is the action to take on valid input.
```rust
pub fn prompt_user(prompt: S, siv: &mut Cursive, out: &F, and_then: &A)
where F: Fn(&str) -> Result + 'static, S: Into + 'static,
A: Fn(&mut Cursive, Ret) + 'static{
siv.add_layer(Dialog::around(EditView::new()
.on_submit(move |s, txt| {
match out(txt) {
Ok(r) => and_then(s, r),
Err(es) => prompt_user(prompt, s, out, and_then)
}
})))
}
```
Currently, this doesn't compile: the lambda in `on_submit` cannot be `'static`. Hence, I was wondering if there was a better way to get this sort of functionality. Or, perhaps, could `EditView` accept non-static lambdas (I presume the lambda would have to outlive the view, but that's all, right)?
More generally, is there a reason the lambda has to be static?
Contributor guide
Assessment
This issue has not been assessed yet.