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


#1

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:

https://play.rust-lang.org/?gist=0a60dbe186340886d8383d86a612a97e&version=stable&mode=debug&edition=2015

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?


#2

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.


#3

That works quite nicely, thanks!


#4

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