Skip to main content

net_kit/
network_status.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
5pub enum NetworkStatus {
6    /// Network is unavailable.
7    #[default]
8    Unavailable,
9    /// Network is available.
10    Available,
11}
12
13impl NetworkStatus {
14    /// The variant name as a static string (e.g. `"Available"`).
15    ///
16    /// Used both by the [`fmt::Display`] implementation and as a stable,
17    /// human-readable label when forwarding the status to logging.
18    pub const fn name(&self) -> &'static str {
19        match self {
20            NetworkStatus::Unavailable => "Unavailable",
21            NetworkStatus::Available => "Available",
22        }
23    }
24}
25
26impl fmt::Display for NetworkStatus {
27    /// Renders the variant name, so `to_string()` yields `"Available"` /
28    /// `"Unavailable"` rather than a structural form.
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        f.write_str(self.name())
31    }
32}