Hey all, just wondering if there are blogs or podcasts out there that cover common design patterns in Rust. I’m a Java dev and have tried a few times to get into Rust, but it feels like I’m solving problems in a way that aren’t the most optimal for Rust because I’m still in that Java mindset.

Anyway I’m working on an XMPP client and my current challenge is working to implement some sort of event/listener system where I can trigger functions when I receive certain XMPP message types.

I put together a simple XML parser to deserialize (haven’t done serialisation yet) messages which I can then determine the type of message it is. I was thinking maybe an event driven setup might work best here but not sure where to start in a Rust idiomatic way.

The idea would be we receive a Proceed message for TLS negotiation, this would trigger the tls_upgrade function which itself will send messages and need to react to the response as part of the negotiation step. But, again I’m not sure this would even be the best approach.

What I’m doing now is calling the tls_upgrade function which will do its own handling of sending a negotiation message, then looping on read_line on the stream hoping that the next message is the next needed message in the negotiation process.

So some advice on common patterns used in Rust in blog form or even podcasts would be a good learning resource.

Cheers.

  • vas@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    5 days ago

    From my experience, Rust programmers use the terminology of “design patterns” much less frequently, comparing to how it’s used in the Java world. I have only a year or two of Java experience, having quickly moved to Scala for more many years after that, but I think I vaguely remember the vibe around it in Java and it just doesn’t exist.

    In terms of “building blocks” in the Rust world, I’d say there are the “synchronization primitives” like RwLock’s, Arc’s and such, there is the big and sometimes difficult async, there is message passing concurrency via e.g. std::sync::mpsc. I haven’t heard much about actor systems, they’re much less used than e.g. Akka of the Scala(/Java?) world I think. To experiment and design a solution, you probably want to read about these “building blocks” and what they’re meant for. For this particular case I don’t have a quick advice unfortunately. Maybe look from existing XMPP libs and go from what they have.

    On a personal/user level, I’d love to see an XMPP client in Rust!

    • Matty_r@programming.devOP
      link
      fedilink
      arrow-up
      1
      ·
      4 days ago

      Thanks, yea from what I gather the term is “idiomatic Rust” but its the same thing really.

      As far as the client goes,I’ve made some slow but decent progress. I’ve got it connecting using STARTTLS and authenticating, and have been able to send a message to a user. I’ve got the user interface going as well using Egui and Bevy, its not “connected” to the back end yet, but its been super easy to get going.