mrkeen 3 days ago

STM is Haskell's feature for safe shared&mutable state.

What is Rust's feature for safe shared&mutable state?

2
zozbot234 3 days ago

Relevant: https://github.com/Marthog/rust-stm which has usage instructions. It's memory safe as defined in Safe Rust, but unlike the Haskell implementation it's not "safe" in a correctness sense, because Rust does not afford the same control about mutability and purity. (At least, not yet - future additions to the language may improve this somewhat.)

speed_spread 3 days ago

That would be Arc<Mutex<T>>, which works but is no STM.

Philpax 3 days ago

Additionally, the actor model is pretty easy to implement: https://ryhl.io/blog/actors-with-tokio/