Skip to main content

orengine/sync/onces/
state.rs

1/// `OnceState` is used to indicate whether the `Once` has been called or not.
2///
3/// # Variants
4///
5/// * `NotCalled` - The `Once` has not been called.
6/// * `Called` - The `Once` has been called.
7#[derive(Eq, PartialEq, Copy, Clone, Debug)]
8pub enum OnceState {
9    NotCalled = 0,
10    Called = 1,
11}
12
13impl OnceState {
14    /// Returns the `OnceState` as an `isize`.
15    pub const fn not_called() -> isize {
16        0
17    }
18
19    /// Returns the `OnceState` as an `isize`.
20    pub const fn called() -> isize {
21        1
22    }
23}
24
25impl From<OnceState> for isize {
26    fn from(state: OnceState) -> Self {
27        state as Self
28    }
29}
30
31impl TryFrom<isize> for OnceState {
32    type Error = ();
33
34    fn try_from(value: isize) -> Result<Self, Self::Error> {
35        match value {
36            0 => Ok(Self::NotCalled),
37            1 => Ok(Self::Called),
38            _ => Err(()),
39        }
40    }
41}