Skip to content

Instantly share code, notes, and snippets.

@luizdepra
Last active September 10, 2024 21:32
Show Gist options
  • Save luizdepra/74a93985600eea90e56b3fa5e72b8e3e to your computer and use it in GitHub Desktop.
Save luizdepra/74a93985600eea90e56b3fa5e72b8e3e to your computer and use it in GitHub Desktop.
Typestate with Rust

Typestate with Rust

// States
trait ResourceState {}
#[derive(Debug)]
struct PendingState;
#[derive(Debug)]
struct CreatingState;
#[derive(Debug)]
struct CreationErrorState {
code: u32,
message: String,
};
#[derive(Debug)]
struct AvailableState;
#[derive(Debug)]
struct DeletingState;
#[derive(Debug)]
struct DeletionErrorState {
code: u32,
message: String,
};
#[derive(Debug)]
struct DeletedState;
// Resource
#[derive(Debug)]
struct Resource<S: ResourceState> {
id: u64,
name: String,
state: S,
}
impl Resource<>
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment