15
Patterns for Modeling Overlapping Variant Data in Rust
(mcmah309.github.io)
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Credits
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 implementFileState
, iestruct File<TState: FileState>
.Uploading
,Staged
, andCommitted
.Uploading
contains a buffer and some block IDs,Staged
has no buffer but includes the block IDs, andCommitted
is 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.