Unfortunately, Rust cannot exactly replicate the design of goroutines without sacrificing other design goals such as good interoperability with C/++ and zero-cost abstractions (aka “you don’t pay run-time performance for features that you don’t use”).
Click me if you want more details...
Goroutines, as idiomatically used in Go to build scalable servers, essentially require growable task stacks. You can’t achieve scalability to huge number of tasks if it is not possible to keep task stacks very small with careful programming, and you can’t achieve good ergonomics if it’s not possible for task stacks to grow larger as needed. Add to this that it’s impossible to predict program stack size in advance in a fully general way, and the need for stack growth becomes clear.
There are two classic ways to implement growable stacks. One is to allow stack segmentation (i.e. make the stack a linked list of memory blocks instead of a single big memory block) and one is to move the old contents of the stack into a new, larger memory block, when the stack grows.
The segmented stack way incurs overhead when the stack pointer moves around (since there’s a need to check if one needs to move to the previous stack block or allocate a new one), and degrades interoperability with C because e.g. you can’t easily pass a pointer to an array on the stack to a C function since it may not be contiguous. The “move everything around” way also costs performance on stack growth, and breaks many low-level use cases because it means that pointers to the stack of Rust threads cannot be relied upon for extended periods of time as they may be invalidated by things moving around.
You can write Rust programs in CSP style by using OS threads communicating via
mpsc channels, but it will be more heavyweight than Go’s approach because OS threads are a more heavyweight abstraction than goroutines (more expensive to create on some OSes, eat up more RAM, etc).
As a more efficient alternative, you can also explore library-level implementations of the Actor paradigm, which is closely related to CSP. A well-loved library in this area is Actix.
I’m not sure if any of these libraries has been ported to wasm yet, though.