Go vs. Rust

I’ve been writing Rust at work for about 4 years now, and while I have a good intermediate grasp on the language, I’m by no means an expert. There’s a lot of things I still want to explore and learn in Rust. The dyn keyword, phantom data, Box and Pin, etc…
1. Directions on channels as types#
<- chan struct{}{}or-> chan struct{}{}is super useful for easy reading and understanding of data flow- you can of course just pass around a channel
chan struct{}{}but I tend to prefer bound and directed channels. - Rust has no equivalent syntax for typing the channel direction
- you can of course just pass around a channel
- Interfaces are much easier to pass into functions in Go
- If you want to pass a trait as a function type in Rust, you can, but it opens up a whole box of
dyntroubles because of the ownership implications. - Again, possible, but difficult.
- If you want to pass a trait as a function type in Rust, you can, but it opens up a whole box of
- You can make args require an impl, e.g.
arg1: impl MyTraitwill require that the arg1 argument to the function in example can be anything that implementsMyTrait.- In rust this is possible but harder to do. Rust’s generic syntax can be a little bit dense sometimes, though I only slightly prefer Go’s constraint syntax.
2. The Simplicity#
- I like Rust a lot, but I think that it’s heavy handed sometimes for what I want. Go still hits a sweet spot.
- Everything in Go has a Go answer, but sometimes this does result in some Magic.
- The date time in the standard library is a great example of Magic in Go.
3. Rust Things That I Miss in Go#
- Pattern matching
- The match keyword is so strong and allows for extremely succinct handling.
- I almost always prefer a match to an if/then/else flow. It reads so much better to me, and the exhaustive match makes it very clear.
- The memory first approach has to be honored.
- Rust simply makes Go’s mantra of “share memory by communicating, don’t communicate by sharing memory” into a compile time rule.
- I’ve described this as Rust “front-loading” the memory management design of a given program.
- It’s very nice for the actor pattern and similar patterns.
- Rust simply makes Go’s mantra of “share memory by communicating, don’t communicate by sharing memory” into a compile time rule.
- If it compiles I’m certain it will run, and if it will crash, that’s on me.
read other posts