if0ne opened issue #12588:
Hi there!
I want to do something like this:
store.limiter_async(move |_| &mut memory_limiter);The memory limiter is created and configured outside of the store creation.
However, this is currently impossible:
store.limiter_async(move |_| &mut memory_limiter); | -------- ^^^^^^^^^^^^^^^^^^^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | | | | | has type `&'2 mut SharedCtx` | lifetime `'1` represents this closure's body | = note: closure implements `FnMut`, so references to captured variables can't escape the closureShould I move the limiter into the store’s data, or is this something that could be fixed in future releases?
alexcrichton commented on issue #12588:
Yes for now you'll need to place the limiter in the store's data itself, as Rust's closures don't allow this style of borrowing where you return a borrow of the captured data itself. As for fixing this and/or supporting this, it's in theory possible yeah and would likely require adjusting bounds here. For now does moving into the store work for you?
if0ne commented on issue #12588:
Yes, moving the limiter into the Store works fine for me. Thanks you
alexcrichton closed issue #12588:
Hi there!
I want to do something like this:
store.limiter_async(move |_| &mut memory_limiter);The memory limiter is created and configured outside of the store creation.
However, this is currently impossible:
store.limiter_async(move |_| &mut memory_limiter); | -------- ^^^^^^^^^^^^^^^^^^^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | | | | | has type `&'2 mut SharedCtx` | lifetime `'1` represents this closure's body | = note: closure implements `FnMut`, so references to captured variables can't escape the closureShould I move the limiter into the store’s data, or is this something that could be fixed in future releases?
alexcrichton commented on issue #12588:
Ok great! In that case I'll close this for now, but if that becomes problematic I can also reopen for a future feature to update the siganture of this function.
Last updated: Feb 24 2026 at 04:36 UTC