-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
I was looking into using references instead of passing around a context, and it seems tricky. Just wanted to record somewhere how far I got.
This is close, but doesn't quite work:
struct State<F, V> {
f: F,
state: String,
phantom: std::marker::PhantomData<V>,
}
impl<'a, V: View + 'a, F: Fn(&'a String) -> V + 'a> View for State<F, V> {
fn draw(&self) {
(self.f)(&self.state).draw();
}
}
The problem is in F: Fn(&'a String) -> V + 'a
. This says the entire closure cannot outlive the String passed in. That's not quite what we want. It's ok if the closure lives longer. What we want is for the return type (V
) to live as long as the String passed in.
What we want is something like F: for<'a> Fn(&'a String) -> V<'a>
where V
is a higher-kinded-type, but rust doesn't (yet) have this feature.
Metadata
Metadata
Assignees
Labels
No labels