I'm not 100% sure what I want really from the lifetimes. It's just a sort of 'this works'.
From my point of view, they seem to exist to allow a continuation. E.g when the next "Input" arrives, run this function. I don't mind restricting the caller somewhat, but I feel like if the inputs all become 'static, that's probably not the best program.
Ideally if there was a way to express the binder, F, to be a closure, but it can all be on the heap to avoid a lifetime?, that would be great. I think I am hitting lifetime problems because if someone passes a closure, obviously that needs to live long enough for the 'arbitrary later date' that it gets evaluated.
What I would really like is for my structure to 'own' the closure, and the closed over variables, in a read-only fashion. It should be 'immutable' and clone able from my perspective. However I am struggling to get the compiler to be happy with this.
pub fn bind<I, O, RA, RB, F>(m: Coroutine<I, O, RA>, f: F) -> Coroutine<I, O, RB>
where
F: Copy + FnOnce(RA) -> Coroutine<I, O, RB>,
{
match m.resume {
CoroutineState::Done(ra) => f(ra),
CoroutineState::Yield(output, ra) => {
let state = bind(*ra, f);
let resume = CoroutineState::Yield(output, Box::new(state));
Coroutine { resume }
}
CoroutineState::Await(ra) => {
let state = move |input: I| -> Coroutine<I, O, RB> {
let next = ra(input);
bind(next, f)
};
let resume = CoroutineState::Await(Box::new(state));
Coroutine { resume }
}
}
}
At the moment I've simplified it to the above, but F,I etc don't live long enough. This confuses me a bit, as I am happy to have them be 'owned', by the coroutine structure, but I can't figure out how to do that. I would have thought liberal use of copy/clone/box is making me responsible for them, but the compiler is still not happy 
EDIT:
I worked on it more, and I think the key is in my suspend function
pub fn suspend<I, O, R, F>(f: F) -> Coroutine<I, O, R>
where
F: Fn(I) -> Coroutine<I, O, R> + Copy,
{
let resume = CoroutineState::Await(Box::new(f));
Coroutine { resume }
}
E.g If I can figure out how to pass a closure, F, and store that completely owned and on the heap, I will be good. It's almost like I want a more restricted Fn closure, in which none of the values are borrowed, they are all owned. Unsure if this trait exists.