diff --git a/crates/xy-protocol/src/lib.rs b/crates/xy-protocol/src/lib.rs index a344f10..33f24e9 100644 --- a/crates/xy-protocol/src/lib.rs +++ b/crates/xy-protocol/src/lib.rs @@ -1 +1,5 @@ //! Wire types and config schema shared between the xy daemon and CLI. + +pub mod state; + +pub use state::ServerState; diff --git a/crates/xy-protocol/src/state.rs b/crates/xy-protocol/src/state.rs new file mode 100644 index 0000000..3fced82 --- /dev/null +++ b/crates/xy-protocol/src/state.rs @@ -0,0 +1,31 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum ServerState { + Stopped, + Starting, + Running, + Restarting, + Failed, + Stopping, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn serializes_to_kebab_case() { + assert_eq!( + serde_json::to_string(&ServerState::Restarting).unwrap(), + "\"restarting\"" + ); + } + + #[test] + fn deserializes_from_kebab_case() { + let s: ServerState = serde_json::from_str("\"failed\"").unwrap(); + assert_eq!(s, ServerState::Failed); + } +}