this post was submitted on 12 Jul 2025
14 points (100.0% liked)

Rust

7165 readers
41 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
 

An interesting article that lays out a problem and goes through a few different solutions, some of which I haven't thought about much before.

I'm working on a video game in Rust, and I'm running into this kind of modelling problem when it comes to keeping track of the game state. So far I've refactored something that resembles Approach 5 into something that looks more like Approach 3. As I get more confident about the final shape of the data, it (seemingly) becomes a better idea to represent it in a more structured way.

you are viewing a single comment's thread
view the rest of the comments
[–] chrash0@lemmy.world 7 points 5 days ago* (last edited 5 days ago)

one that i’ve used in the past but isn’t mentioned here is type state based. when developing a file upload service i have a File struct with different states that implement FileState, ie struct File<TState: FileState>. Uploading, Staged, and Committed. Uploading contains a buffer and some block IDs, Staged has no buffer but includes the block IDs, and Committed is just a marker. they can have different methods based on their type state like impl File<Uploading>. this gives us the type safety of, for example, not allowing a partially uploaded file to be committed, while still sharing some state like ID, etc.