tonic_health/
lib.rs

1//! A `tonic` based gRPC healthcheck implementation.
2//!
3//! # Example
4//!
5//! An example can be found [here].
6//!
7//! [here]: https://github.com/hyperium/tonic/blob/master/examples/src/health/server.rs
8
9#![warn(
10    missing_debug_implementations,
11    missing_docs,
12    rust_2018_idioms,
13    unreachable_pub
14)]
15#![doc(
16    html_logo_url = "https://raw.githubusercontent.com/tokio-rs/website/master/public/img/icons/tonic.svg"
17)]
18#![deny(rustdoc::broken_intra_doc_links)]
19#![doc(html_root_url = "https://docs.rs/tonic-health/0.12.3")]
20#![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")]
21#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
22#![cfg_attr(docsrs, feature(doc_auto_cfg))]
23
24use std::fmt::{Display, Formatter};
25
26mod generated {
27    #![allow(unreachable_pub)]
28    #![allow(missing_docs)]
29    #[rustfmt::skip]
30    pub mod grpc_health_v1;
31
32    /// Byte encoded FILE_DESCRIPTOR_SET.
33    pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/grpc_health_v1.bin");
34
35    #[cfg(test)]
36    mod tests {
37        use super::FILE_DESCRIPTOR_SET;
38        use prost::Message as _;
39
40        #[test]
41        fn file_descriptor_set_is_valid() {
42            prost_types::FileDescriptorSet::decode(FILE_DESCRIPTOR_SET).unwrap();
43        }
44    }
45}
46
47/// Generated protobuf types from the `grpc.health.v1` package.
48pub mod pb {
49    pub use crate::generated::{grpc_health_v1::*, FILE_DESCRIPTOR_SET};
50}
51
52pub mod server;
53
54/// An enumeration of values representing gRPC service health.
55#[derive(Copy, Clone, Debug, PartialEq, Eq)]
56pub enum ServingStatus {
57    /// Unknown status
58    Unknown,
59    /// The service is currently up and serving requests.
60    Serving,
61    /// The service is currently down and not serving requests.
62    NotServing,
63}
64
65impl Display for ServingStatus {
66    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
67        match self {
68            ServingStatus::Unknown => f.write_str("Unknown"),
69            ServingStatus::Serving => f.write_str("Serving"),
70            ServingStatus::NotServing => f.write_str("NotServing"),
71        }
72    }
73}
74
75impl From<ServingStatus> for pb::health_check_response::ServingStatus {
76    fn from(s: ServingStatus) -> Self {
77        match s {
78            ServingStatus::Unknown => pb::health_check_response::ServingStatus::Unknown,
79            ServingStatus::Serving => pb::health_check_response::ServingStatus::Serving,
80            ServingStatus::NotServing => pb::health_check_response::ServingStatus::NotServing,
81        }
82    }
83}