A Gopher Meets a Crab

(miren.dev)

28 points | by radimm 2 days ago

3 comments

  • joshka 1 hour ago
    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.
    • loeg 1 hour ago

        Result<(), ()>
      
      Is pretty weird, though, no? Why would you want a unit value / error type?
      • MrJohz 33 minutes ago
        It's basically doing the same thing that, say, `return true` might do to indicate a function succeeded, but with more explicit types. However, because it uses `Result`, it can be used with the `try`/question mark operator which can be convenient in some situations.

        That said, a couple of the examples here feel a bit strange - they're clever things you can do, but they're not necessarily things you often have to do, particularly for a relatively simple task like this. I think the problem with the author's approach is that they can't distinguish between "weird because Rust is weird" and "weird because the LLM generated bad code", because they (understandably) don't have enough experience in what good Rust code looks like.

      • stingraycharles 23 minutes ago
        It’s the equivalent of Haskell’s Either, with Option being the equivalent of Maybe. They’re fairly well-defined idioms.
      • tux3 33 minutes ago
        Sometimes you just want a fancy boolean. The advantage is that Result has all the Result APIs and you can compose it with other Results, but otherwise this is just a success bool.
    • tancop 55 minutes ago
      [dead]
  • RobotToaster 59 minutes ago
    Was anyone else expecting OpenClaw over gopher protocol?
    • coqadoodle 19 minutes ago
      I was looking forward to retro deep-dive back into the 90s. I just couldn't figure out where the crab fit in.
  • nothinkjustai 11 minutes ago
    Um? Person vibe codes Rust. Output is stupid. The conclusion is either

    a) Vibe coding produces bad code

    b) Rust is weird

    Somehow we’re supposed to accept b as the answer? Give me a break….