Can this lifetime constaint be expressed, or should I refactor my code?

I’m trying to switch a Vec<u8> field in a data structure to a &[u8], but I’m having difficulty modifying the calling code correctly. I’ve made a simple example that captures the essence of what I want to do:

Since I’m unable to properly get this to work with the next lambda, should I instead move the logic that picks the lambda inside the handle function and avoid the pain of complicated lifetime annotations altogether?

It seems to work this way: Playground. I think when you wrote TrivialWrapper::next that referred to the single function TrivialWrapper::<'a>::next for some 'a chosen within main, whereas you really need something that refers to the family of functions TrivialWrapper::<'a>::next across all possible choices of 'a because that lifetime will be determined only within handle.

1 Like

That works quite nicely, thanks!

Take a look at this SO answer on HRTB if you’d like to understand it a bit better.