Last active
          September 10, 2024 21:32 
        
      - 
      
- 
        Save luizdepra/74a93985600eea90e56b3fa5e72b8e3e to your computer and use it in GitHub Desktop. 
    Typestate with Rust
  
        
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // 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