logoalt Hacker News

dxxvitoday at 1:22 AM2 repliesview on HN

> It's exceedingly rare to see any sort of global mutable state I know a bit of Rust, so you don't need to explain in details. How to use a local cache or db connection pool in Rust (both of them, IMO, are the right use case of global mutable state)?


Replies

adastra22today at 2:47 AM

You wrap it in a mutex and then it is allowed.

Global state is allowed. It just has to be thread safe.

thereintoday at 1:30 AM

Why does that have to be global? You can still pass it around. If you don't want to clobber registers, you can still put it in a struct. I don't imagine you are trying to avoid the overhead of dereferencing a pointer.