diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-30 09:29:12 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-30 09:29:12 -0500 |
commit | 83ffcc667999879197508aba0d1f910ca7cb000b (patch) | |
tree | f4eb596e5cbd6957f50a642b4e85160db0448969 /protocol/src/move_result.rs | |
parent | 6b1f611e4ae1c719acd7d0d8dd5716dd0d52b255 (diff) |
Populate result after a board is played
Diffstat (limited to 'protocol/src/move_result.rs')
-rw-r--r-- | protocol/src/move_result.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/protocol/src/move_result.rs b/protocol/src/move_result.rs new file mode 100644 index 0000000..8dad6ef --- /dev/null +++ b/protocol/src/move_result.rs @@ -0,0 +1,23 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)] +pub enum MoveResult<Current, Next> { + Current(Current), + Next(Next), +} + +impl<Current, Next> MoveResult<Current, Next> { + pub fn current(self) -> Result<Current, anyhow::Error> { + match self { + MoveResult::Current(o) => Ok(o), + MoveResult::Next(_) => Err(anyhow::anyhow!("Not in current state")), + } + } + + pub fn next(self) -> Result<Next, anyhow::Error> { + match self { + MoveResult::Next(f) => Ok(f), + MoveResult::Current(_) => Err(anyhow::anyhow!("Not in next state")), + } + } +} |