service_probe_common/
lib.rs

1// SPDX-FileCopyrightText: OpenTalk Team <mail@opentalk.eu>
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! # Service probe State type
6//!
7//! This crate provides the definition of the `ServiceState` type.
8#![deny(
9    bad_style,
10    missing_debug_implementations,
11    missing_docs,
12    overflowing_literals,
13    patterns_in_fns_without_body,
14    trivial_casts,
15    trivial_numeric_casts,
16    unsafe_code,
17    unused,
18    unused_extern_crates,
19    unused_import_braces,
20    unused_qualifications,
21    unused_results
22)]
23
24/// The state of a service
25#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
26pub enum ServiceState {
27    /// The service is starting up.
28    Up,
29
30    /// The service is started and ready to process requests.
31    Ready,
32}
33
34impl ServiceState {
35    /// Get the [`str`] representation of the [`ServiceState`].
36    pub const fn as_str(&self) -> &'static str {
37        match self {
38            ServiceState::Up => "UP",
39            ServiceState::Ready => "READY",
40        }
41    }
42}
43
44impl std::fmt::Display for ServiceState {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        write!(f, "{}", self.as_str())
47    }
48}