tower_lsp/service/
state.rs1use std::fmt::{self, Debug, Formatter};
4use std::sync::atomic::{AtomicU8, Ordering};
5
6#[derive(Clone, Copy, Debug, PartialEq)]
8#[repr(u8)]
9pub enum State {
10 Uninitialized = 0,
12 Initializing = 1,
14 Initialized = 2,
16 ShutDown = 3,
18 Exited = 4,
20}
21
22pub struct ServerState(AtomicU8);
24
25impl ServerState {
26 #[inline]
27 pub const fn new() -> Self {
28 ServerState(AtomicU8::new(State::Uninitialized as u8))
29 }
30
31 #[inline]
32 pub fn set(&self, state: State) {
33 self.0.store(state as u8, Ordering::SeqCst);
34 }
35
36 #[inline]
37 pub fn get(&self) -> State {
38 match self.0.load(Ordering::SeqCst) {
39 0 => State::Uninitialized,
40 1 => State::Initializing,
41 2 => State::Initialized,
42 3 => State::ShutDown,
43 4 => State::Exited,
44 _ => unreachable!(),
45 }
46 }
47}
48
49impl Debug for ServerState {
50 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
51 self.get().fmt(f)
52 }
53}