Please read the book fully before starting any real project. It will save you headaches later
post
I would say:
- Avoid async if you can. It's way more difficult and error prone than non-async Rust. Unfortunately a lot of web stuff insists on async.
- Don't be afraid to
.clone()stuff to fix lifetime errors. It's not optimal but consider that in C++ everything is pretty much cloned by default, and nobody ever said C++ was slow. - Use
anyhow::Resultfor error handling. It's the easiest option.
Thanks! One of the reasons for choosing Rust was actually concurrency. So I’m building a bunch of endpoints that connect with some microservices and I expect to have many simultaneous requests. I’m honestly not like super senior but for the Python backends we’ve been building we always made everything asynchronous so I kinda got the impression that that would be necessary for my use cases. Should I also be careful with async functions when using Poem?
Rust async has quite a lot of footguns that other async runtimes don't have. There are some listed here:
- https://www.qovery.com/blog/common-mistakes-with-rust-async/
- https://google.github.io/comprehensive-rust/concurrency/async-pitfalls.html
- https://bitbashing.io/async-rust.html
- https://carllerche.com/2021/06/17/six-ways-to-make-async-rust-easier/
Honestly if you're using an async Rust web framework (which they pretty much all are) it may be the path of least resistance to still use async. But in general I would strongly prefer scoped threads, channels, rayon etc.
many simultaneous requests
Unlikely to be so many that threads would be an issue.
Thanks! This is something I had no idea could be an issue. I just started standing up all the dummy functions for the different layers so I’ll take a step back now and review the resources you pointed me at. Also, in the Poem docs I don’t see them using async functions either. I’m very glad I asked.
@echodrift there's something funny going on here. I dunno what tho! Is this image hidden on your website somewhere? Didn't see it in the post.
Uhm, yeah, that's interesting. Programming.dev is a Lemmy instance, which is basically federated Reddit, so this could be any sort of user-submitted image.
Unfortunately, the screenshot you posted doesn't make it to this side of the federation, so I'll embed it for people here:

@Ephera ah, the fediverse, what can't it make slightly broken? 🤣
Re: programming dot dev, that makes more sense - I didn't look around much but as a reddit-a-like it surely has links to "nearby" content hanging out around the main body of the page, and whatever logic in Mastodon (or my client?) that seeks an image to embed must've reached a bit far.
Honestly I have no idea wtf that is and luckily I don’t see that when I open the page! Seriously wtf
I always recommend these tutorials to folks for learning about ownership, as they offer a very visual explanation: http://intorust.com/
You can skip the first two chapters.
all 17 comments