Skip to main content

orx_concurrent_option/
states.rs

1use core::sync::atomic::Ordering;
2
3/// State represented as u8.
4pub type StateU8 = u8;
5
6pub const ORDER_LOAD: Ordering = Ordering::Acquire;
7pub const ORDER_STORE: Ordering = Ordering::SeqCst;
8
9/// State where the optional does not have a value.
10pub const NONE: StateU8 = 0;
11/// State where the optional's value is being transitioned.
12pub const RESERVED: StateU8 = 1;
13/// State where the optional contains a value.
14pub const SOME: StateU8 = 2;
15
16/// Concurrent state of the optional.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum State {
19    /// Optional has no value.
20    None,
21    /// Optional has some value.
22    Some,
23    /// Optional is currently reserved for a mutation.
24    Reserved,
25}
26
27impl State {
28    #[allow(clippy::panic, clippy::missing_panics_doc)]
29    pub(crate) fn new(state: StateU8) -> Self {
30        match state {
31            NONE => Self::None,
32            SOME => Self::Some,
33            RESERVED => Self::Reserved,
34            _ => panic!("should be either of the three valid states"),
35        }
36    }
37}