mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 08:55:40 +01:00
refactor: constified enum -> regular enum
This commit is contained in:
@@ -137,7 +137,6 @@ impl fmt::Debug for Database {
|
||||
DbState::Uninitialized => "uninitialized".to_string(),
|
||||
DbState::Initializing => "initializing".to_string(),
|
||||
DbState::Initialized => "initialized".to_string(),
|
||||
x => format!("invalid ({x:?})"),
|
||||
};
|
||||
debug_struct.field("db_state", &db_state_value);
|
||||
|
||||
|
||||
@@ -246,18 +246,21 @@ pub enum AutoVacuumMode {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
pub struct DbState(usize);
|
||||
#[repr(usize)]
|
||||
pub enum DbState {
|
||||
Uninitialized = Self::UNINITIALIZED,
|
||||
Initializing = Self::INITIALIZING,
|
||||
Initialized = Self::INITIALIZED,
|
||||
}
|
||||
|
||||
impl DbState {
|
||||
#![allow(non_upper_case_globals)]
|
||||
pub const Uninitialized: Self = Self(0);
|
||||
pub const Initializing: Self = Self(1);
|
||||
pub const Initialized: Self = Self(2);
|
||||
pub(self) const UNINITIALIZED: usize = 0;
|
||||
pub(self) const INITIALIZING: usize = 1;
|
||||
pub(self) const INITIALIZED: usize = 2;
|
||||
|
||||
#[inline]
|
||||
pub fn is_initialized(&self) -> bool {
|
||||
matches!(*self, DbState::Initialized)
|
||||
matches!(self, DbState::Initialized)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,18 +271,23 @@ pub struct AtomicDbState(AtomicUsize);
|
||||
impl AtomicDbState {
|
||||
#[inline]
|
||||
pub const fn new(state: DbState) -> Self {
|
||||
Self(AtomicUsize::new(state.0))
|
||||
Self(AtomicUsize::new(state as usize))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set(&self, state: DbState) {
|
||||
self.0.store(state.0, Ordering::SeqCst);
|
||||
self.0.store(state as usize, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self) -> DbState {
|
||||
let v = self.0.load(Ordering::SeqCst);
|
||||
DbState(v)
|
||||
match v {
|
||||
DbState::UNINITIALIZED => DbState::Uninitialized,
|
||||
DbState::INITIALIZING => DbState::Initializing,
|
||||
DbState::INITIALIZED => DbState::Initialized,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user