Mutable State (Rust & Rocket newbie) #2043
-
How to get mutable application State?
My question is: is this the Right Way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
From my point of view, there’s not much else to do than using Mind if I ask the question. Why would you need to edit a state after liftoff? I see that your example uses users as a storage which I guess would be an abstraction of a db but where would you use mutatable state in a (preferably statless) app? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer: duly noted about Arc + Mutex being the way to go I've had a look into Tokio Mutex: it works great! And I prefer having an await that cannot fail than an unwrap I'm still not sure how to repalce with a match (I mean my understanding is that I should not leave unwraps in prod code since they can panic) as it's not clear to me what I should do with the Err arm of the match. As for your question |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your answer, it clarifies a lot of things for me! |
Beta Was this translation helpful? Give feedback.
Thanks a lot for your answer, it clarifies a lot of things for me!