What are you working on this week? (May. 05, 2024)
from secana@programming.dev to rust@programming.dev on 05 May 2024 09:10
https://programming.dev/post/13670849

Hi rustaceans! What are you working on this week? Did you discover something new, you want to share?

#rust

threaded - newest

Cwilliams@beehaw.org on 05 May 2024 14:49 next collapse

I just started writing a programming language! I’m using pest for the grammar/lexing, which makes if super easy. I built my ast using enums and structs, which makes me appreciate Rust even more. I also am coming to love the way rust handles errors. For example, when there’s an error converting from pest -> ast, it feeds all of the error into into my error type, which is so much easier to handle than making it panic out of the function

fnmain@programming.dev on 05 May 2024 14:55 next collapse

Working on a static site generator for a publication coming out of my high school

nebeker@programming.dev on 05 May 2024 15:13 next collapse

Just learning. I threw together a little CRUD API in Rocket the other day.

Now I’m playing around with Diesel. I don’t love the intermediate New types, coming from EF Core. Is that because Rust ~~~~doesn’t really have constructors?

sugar_in_your_tea@sh.itjust.works on 05 May 2024 16:21 collapse

Can you give an example? Pretty much everything in Diesel is abstracted away through trait macros.

nebeker@programming.dev on 07 May 2024 08:41 collapse

The insert on their Getting Started guide.

let new_post = NewPost { title, body };

diesel::insert_into(posts::table)
    .values(&new_post)
    .returning(Post::as_returning())
    .get_result(conn)
    .expect("Error saving new post")

Of course the other possibility is this guide is very low on abstractions.

sugar_in_your_tea@sh.itjust.works on 07 May 2024 23:53 collapse

Ah, I see. So you’re expecting to have one object for creation, updates, queries, etc.

I work with something like that at work (SQLAlchemy in Python), and I honestly prefer the Diesel design. I build an object for exactly what I need, so I’ll have a handful of related types used for different purposes. In Python, we have a lot of “contains_eager” calls to ensure data isn’t lazy loaded, and it really clutters up the code. With Diesel, that’s not necessary because I just don’t include data that I don’t need for that operation. Then again, I’m not generally a fan of ORMs and prefer to write SQL, so that’s where I’m coming from.

nebeker@programming.dev on 08 May 2024 18:12 collapse

One of my main concerns with this is the potential for making a lot of separate calls to the DB for a complex data structure. Then again there are trade offs to any architecture.

sugar_in_your_tea@sh.itjust.works on 09 May 2024 00:00 collapse

Isn’t the reverse true? If you make separate models for each query, the ORM knows exactly what data you need, so it can fetch it all as once. If you use generic models, the ORM needs to guess, and many revert to lazy loading if it’s not sure (i.e. lots of queries).

That’s at least my experience with SQLAlchemy, we put a lot of effort in to reduce those extra calls because we’re using complex, generalized structures.

[deleted] on 05 May 2024 15:15 next collapse

.

green_dot@le.fduck.net on 05 May 2024 16:14 next collapse

reverse proxy using tokio and hyper, there are few things to figure out on high traffic sites, it doesn’t work as well compared to nginx after a certain threshold.

sugar_in_your_tea@sh.itjust.works on 05 May 2024 16:24 next collapse

That’s too bad, I was thinking of replacing our nginx proxy with Rust. We need a little logic, so we currently have nginx -> gateway service -> microservice, and I was hoping to drop nginx. Maybe I still can, but it sounds like there would be some tradeoffs.

green_dot@le.fduck.net on 05 May 2024 18:28 collapse

this might be more on me writing shit code than on tokio/hyper. give it a go.

Nereuxofficial@programming.dev on 05 May 2024 16:49 collapse

Maybe Cloudflare’s pingora suits this purpose better given that it is being used by cloudflare to proxy traffic at a large scale

green_dot@le.fduck.net on 05 May 2024 17:32 collapse

Yeah, I’m looking at it, will probably rewrite the logic using Pingora. or maybe I did something wrong. Not sure if its something using the hyper legacy client, that has connection pooling, maybe there’s something there to improve.

or maybe the use of RwLock to share the config struct is reaching some limits. Will try using parking_lot to see if anything changes.

Nereuxofficial@programming.dev on 05 May 2024 16:54 next collapse

A general purpose memory allocator although this is really much a work in progress i think there are some good opportunities for otimization in a memory allocator for rust.

For example Rust gives you the size of memory region to free, which means the allocator does not have to track that.

zinderic@programming.dev on 10 May 2024 13:14 next collapse

Tamagotchi like game 😂

peanutbutter_gas@lemm.ee on 11 May 2024 04:49 collapse

Made a discord soundboard bot. Some simple text channel commands get the bot to join whatever voice channel you’re in and get the bot to display available sounds as buttons in the text channel. It actually works really well and sounds great.

My friends and I just wanted a bigger soundboard without having to pay for it.