How to design an alternative to current closure trait system without the return type limitation?

I recently hit this closure return type limitaion (i.e. Output can not contain 'self lifetime). Following discussions from that thread, I attempt to use GAT to define FnMut just to see what can be done without the super-trait relationships, but can not find a definition of a FnMut (or Fn) that is general enough:

trait FnMut<Arg> {
    type Output<'a> where Self: 'a;
    // What if we actually want to use a lifetime in the argument type,
    // or one captured by the closure type?
    fn call<'lself>(&'lself mut self, arg: Arg) -> Self::Output<'lself>;
}

Is there anything I can do to make a general enough FnMut?

There's no way to cover every possible set of relationships in the trait definition (e.g. return the intersection of a lifetime in Self and another in Arg).

Thanks for your clarification! I was kind of expecting this. At first I was annoyed by this closure return type limitation, but after trying to understand how things work under the hood, I can't really complain: it's really hard to come up with a perfect design.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.