This question suggests that you don't have yet a clear distinction about the fn
hierarchy:
taken from here.
Warp's filter function need to implement the Fn trait.
This means that you cannot access the outer context(read: environment).
The first time AndThen call your closure, the function will consume the "only" tmp variable available, thus it won't be available for future calls. Since the closure it's taking ownership of its context, it means it's implementing FnOnce.
As suggested by @msrd0 in the comment, probably this is solvable by moving that call in the function, but I would need an MRE to be certain about it.