Here's an example of code that I want to work.
struct StaticSystem<In, Out> {
run: &'static (dyn Fn(In) -> Out + Sync + Send),
}
fn example(_input: &str) {}
fn main() {
let system = StaticSystem {
run: &example,
};
let test = &String::from("test");
(system.run)(test);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0310]: the parameter type `In` may not live long enough
--> src/main.rs:2:10
|
2 | run: &'static (dyn Fn(In) -> Out + Sync + Send),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the reference type `&'static (dyn Fn(In) -> Out + Send + Sync + 'static)` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound...
|
1 | struct StaticSystem<In: 'static, Out> {
| +++++++++
error[E0310]: the parameter type `Out` may not live long enough
--> src/main.rs:2:10
|
2 | run: &'static (dyn Fn(In) -> Out + Sync + Send),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the reference type `&'static (dyn Fn(In) -> Out + Send + Sync + 'static)` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound...
|
1 | struct StaticSystem<In, Out: 'static> {
| +++++++++
For more information about this error, try `rustc --explain E0310`.
error: could not compile `playground` (bin "playground") due to 2 previous errors
The issue is I can't figure out how to have something like:
&'static (dyn for<'a> Fn(In: 'a) -> Out: 'a + Sync + Send)
Is there a way to restrict the lifetime of In
and Out
to be for<'a>
?