this post was submitted on 12 Jul 2025
14 points (100.0% liked)
Rust
7509 readers
5 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
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
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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
Filestruct with different states that implementFileState, iestruct File<TState: FileState>.Uploading,Staged, andCommitted.Uploadingcontains a buffer and some block IDs,Stagedhas no buffer but includes the block IDs, andCommittedis just a marker. they can have different methods based on their type state likeimpl 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.