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