// file: ks-store/src/contracts/health.rs // version: 3 //! Backend-neutral health contracts for storage implementations. /// Store backend health status. #[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub enum StoreHealthStatus { /// Health is not known yet. Unknown, /// Backend is reachable and usable. Healthy, /// Backend is reachable but not fully usable. Degraded, /// Backend is not usable. Unhealthy, } /// Store backend health snapshot. #[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct StoreHealthSnapshot { /// Stable backend code such as `postgres` or `sqlite`. pub backend: std::string::String, /// Current health status. pub status: crate::StoreHealthStatus, /// Optional human-readable diagnostic message. pub message: std::option::Option, } impl crate::StoreHealthSnapshot { /// Builds a store health snapshot after minimal validation. pub fn new( backend: impl std::convert::Into, status: crate::StoreHealthStatus, message: std::option::Option, ) -> ks_core::Result { let backend_value = backend.into(); if backend_value.trim().is_empty() { return std::result::Result::Err(ks_core::Error::db( "store health backend must not be empty", )); } return std::result::Result::Ok(Self { backend: backend_value, status, message }); } } #[cfg(test)] mod tests { #[test] fn health_snapshot_rejects_empty_backend() { let result = crate::StoreHealthSnapshot::new( " ", crate::StoreHealthStatus::Unknown, std::option::Option::None, ); assert!(result.is_err()); } }