The weird-looking Rust isn’t really Rust being weird, it’s the type telling the truth.
Result<Option<Result<Message, WsError>>, Elapsed>
That’s three independent “not the happy path” channels: timeout, stream closed,
and websocket error.
The nicer version is not a cleverer match. It’s choosing a domain error shape
and converting into it one layer at a time:
let timed = tokio::time::timeout(duration, receiver.next()).await;
let next = timed.map_err(|_| ReceiveError::Timeout)?;
let item = next.ok_or(ReceiveError::Closed)?;
let msg = item.map_err(ReceiveError::WebSocket)?;
The ugly line is what happens when you have not decided where to normalize the
shape yet.
A much more charitable reading of the article is "here's some observations I found interesting / different". I met the author at the conf and watched their talk. Their perspective was very much in the camp of exploration, learning, wonder, etc. and not in the camp of criticism of either rust or vibe coding practices.
I feel like having an LLM write code in a language you aren't familiar with and then inspecting the results is kind of like hiring someone to speak Spanish for you and then being confused at the weird words they are using. Like, what would make you want to do this?
Learning Go after five years of professional struggle with Rust was a relief; Go feels designed for humans to just get the job done. (not a Google fan!) I'll get a ton of downvote for this but it's ok.
8 comments
[ 3.1 ms ] story [ 26.2 ms ] threadThe nicer version is not a cleverer match. It’s choosing a domain error shape and converting into it one layer at a time:
The ugly line is what happens when you have not decided where to normalize the shape yet.a) Vibe coding produces bad code
b) Rust is weird
Somehow we’re supposed to accept b as the answer? Give me a break….