Replies: 1 comment
-
If you have a tokio |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I think I have another usecase for explicit 'state lifetime in FromRequestParts and would like to know if there's another way of achieving the same.
I have a URL pattern that contains a resource ID. My state is morally equivalent to
Arc<Mutex<HashMap<String, Resource>>>
with theString
corresponding to the resource ID. I would like to have an extractor that extracts "access" to the appropriateResource
.I can make a wrapper
struct ResourceHandle<'a>(&'a mut MappedMutexGuard<'a, Resource>)
and could give it aFromRequestParts<my_state>
implementation, except that I cannot guarantee that the state will outlive'a
.An obvious alternative is to replace
Resource
withArc<Mutex<Resource>>
in my state, and have an extractor for that (which will simply clone the Arc). That is certainly doable (and allows for more concurrency -- the global mutex is held only for the duration of the lookup), but it's somewhat more cumbersome to deal with (each handler has to deal with locking the per-resource mutex).Is there a way of doing some moral equivalent of the former?
axum version
0.7.5
Beta Was this translation helpful? Give feedback.
All reactions