es_entity/
idempotent.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#[must_use]
pub enum Idempotent<T> {
    Executed(T),
    AlreadyApplied,
}

impl<T> Idempotent<T> {
    pub fn was_already_applied(&self) -> bool {
        matches!(self, Idempotent::AlreadyApplied)
    }

    pub fn did_execute(&self) -> bool {
        matches!(self, Idempotent::Executed(_))
    }

    pub fn unwrap(self) -> T {
        match self {
            Idempotent::Executed(t) => t,
            Idempotent::AlreadyApplied => panic!("Idempotent::AlreadyApplied"),
        }
    }
}