This is how far I've managed to minimize my original issue and I don't really understand what is the issue with the lifetime.
use std::future::Future;
struct Worker<FnLoad,LoadFut>
where
LoadFut: Future<Output = ()>,
FnLoad: Fn(&usize) -> LoadFut,
{
load: FnLoad,
}
async fn build(_: &usize) {}
fn main()
{
let w = Worker {
load: build,
};
}
error:
Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
--> src/main.rs:17:13
|
3 | / struct Worker<FnLoad,LoadFut>
4 | | where
5 | | LoadFut: Future<Output = ()>,
6 | | FnLoad: Fn(&usize) -> LoadFut,
7 | | {
8 | | load: FnLoad,
9 | | }
| |_- due to a where-clause on `Worker`...
...
17 | let w = Worker {
| ^^^^^^ doesn't satisfy where-clause
|
= note: ...`FnOnce<(&'0 usize,)>` would have to be implemented for the type `for<'_> fn(&usize) -> impl Future {build}`, for some specific lifetime `'0`...
= note: ...but `FnOnce<(&usize,)>` is actually implemented for the type `for<'_> fn(&usize) -> impl Future {build}`