Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
kujeger
Feb 19, 2004

OH YES HA HA
I've written a couple of relatively busy rust rest API things, and can recommend Axum as a new and tasty thing

Adbot
ADBOT LOVES YOU

kujeger
Feb 19, 2004

OH YES HA HA
Sounds like cargo vendor would be helpful

kujeger
Feb 19, 2004

OH YES HA HA
Rust for backend is really sweet, we're building our latest service in it now. Using sqlx directly for the small amount of db stuff, an ORM seemed a bit overkill.

We're using Axum as our web server/framework. Last i looked at rocket it didn't look as if it was very actively maintained anymore?

Edit: yeah, latest rocket stable is pre-async, and their two 5.0 release candidates are from June 2021 and may 2022. Their repo doesn't appear to see very much activity either.


I've previously built a small microservice using actix-web at work, and using axum this time feels a lot nicer and more ergonomic

kujeger fucked around with this message at 01:42 on Sep 18, 2022

kujeger
Feb 19, 2004

OH YES HA HA
As much as Python may/will be faster at prototyping stuff or whatnot, being really liberal with cloning in Rust will take away a lot of the initial speed bumps.

Remember: keep calm, call .clone() !

kujeger
Feb 19, 2004

OH YES HA HA
You could make State.update consume self:
code:
    pub fn update(self) -> Self {
        Self {
            knowledge: match self.knowledge {
                IncrementalKnowledge::Nothing => IncrementalKnowledge::Stage1 {
                    stage1: Stage1Contents { data: 0 },
                },
                IncrementalKnowledge::Stage1 { stage1 } => IncrementalKnowledge::Stage2 {
                    stage1: stage1,
                    stage2: Stage2Contents { data: 0 },
                },
                IncrementalKnowledge::Stage2 { .. } => IncrementalKnowledge::Nothing,
            },
        }
    }
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3d907d82a9846c10a87311665d1f3fc7

kujeger
Feb 19, 2004

OH YES HA HA
You can also wrap the stage contents in Rc/Arc, allowing you to clone the handle but not the content itself, e.g.

code:
struct Stage1Contents {
  data: u8,
}
[..]
enum IncrementalKnowledge {
  Stage1 {
      stage1: Rc<Stage1Contents>,
  },
}
[..]

          IncrementalKnowledge::Stage1 { stage1 } => IncrementalKnowledge::Stage2 {
              stage1: stage1.clone(),
              stage2: Rc::new(Stage2Contents { data: 0 }),
          },

kujeger fucked around with this message at 10:54 on Feb 22, 2023

kujeger
Feb 19, 2004

OH YES HA HA
Had somehow missed out on mem::replace, very nice!

kujeger
Feb 19, 2004

OH YES HA HA
Seconding the C(++) and Haskell thing; I did a bit of C as a kid and a little Haskell more recently (plus python and perl at work) and found getting into Rust relatively easy and enjoyable, even switching from being a sysadmin to developer full time at roughly the same time. But I've also kept an eye on rust for years, never using it for anything "real" or at work until the last two years or so.

The Java/Kotlin folks at work who've gotten into it had a bit more of a struggle having to think about memory as a thing at all, but now like it a lot.

VSCode plus rust analyzer works very well for me.

kujeger
Feb 19, 2004

OH YES HA HA
I've done a little with Iced, which worked well enough. Am curious about trying slint as well.

It looks like Iced is more focused on giving native looks, while slint is more for custom stuff.

e: oh yeah embedded, i don't think iced is going to work there

kujeger
Feb 19, 2004

OH YES HA HA
Yeah axum is quite nice, we've found it a lot more ergonomic to work with than actix-web was. We even rewrote actix stuff we had into axum so we could standardize the stack.

kujeger
Feb 19, 2004

OH YES HA HA
I don't know if it's best practice or whatnot, but we've been using the strum and strum_macros crates to easily derive Display for just that.

Adbot
ADBOT LOVES YOU

kujeger
Feb 19, 2004

OH YES HA HA

lifg posted:

Exactly that simple.

I haven’t used enum discriminants.

How do I convert from an integer back to the enum? Google is telling me I need to write a try_from function. Is that correct?

There's also this if you already use serde for (de)serializing stuff
https://github.com/dtolnay/serde-repr

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply