summaryrefslogtreecommitdiff
path: root/protocol/src/move_result.rs
blob: 8dad6eff7a318275b56ae37088b37a2b1b3bc862 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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")),
        }
    }
}