You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment there is only version of local_cache method that accepts closure and always returns value. Can we have try_local_cache version that returns Option<&T>. This will simplify code because at the moment I have either wrap my state in Option<> myself or implement Default for my state.
I read in several discussions that to be able to change standard state I have to use Arc/Mutex that I completely agree with but do we really need similar approach for request local state? Is it possible to use the same request in several places asynchronously?
Regarding the second question my use case is following.
Some routes make changes in the database so I want to create a transaction per route and use it for all database changes within route scope.
So my idea was to create a context state that contains transaction object using FromRequest implementation and use it with database operations. And at the and of route execution in the response firing I would just call transaction.commit().
But it's not possible because request local state is immutable.
Is there probably other (more Rocket-agnostic) way to do this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have 2 questions about request local state:
Regarding the second question my use case is following.
Some routes make changes in the database so I want to create a transaction per route and use it for all database changes within route scope.
So my idea was to create a context state that contains transaction object using FromRequest implementation and use it with database operations. And at the and of route execution in the response firing I would just call transaction.commit().
But it's not possible because request local state is immutable.
Is there probably other (more Rocket-agnostic) way to do this?
Beta Was this translation helpful? Give feedback.
All reactions