HACKER Q&A
📣 metadat

Goroutines in Rust?


Does Rust have an equally easy to use concurrency mechanism like Goroutines in Go?

Or a signaling system like channels?


  👤 duped Accepted Answer ✓
Rust uses async/await based concurrency: https://rust-lang.github.io/async-book/01_getting_started/01...

There are a variety of async channel structures, for example:

smol channels: https://docs.rs/smol/0.4.3/smol/channel/index.html

async std channels: https://docs.rs/async-std/1.4.0/async_std/sync/fn.channel.ht...

tokio channels : https://tokio.rs/tokio/tutorial/channels

One difference between Rust and Go is that Rust does not have a runtime by default, which means async/await needs an "executor." Some popular ones are async std, smol, and tokio.

If you want to use OS threads directly for parallelism (which is not concurrency, but is related) then you can use std::thread, and a variety of synchronous channels for inter-thread communication.


👤 verdverm
The original paper "Communicating Sequential Processes" by Tony Hoare is a good read

https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf

Both Erlang and Go use this model. As @duped stated, Rust uses a different model