Skip to main content

ic_query/subnet_catalog/model/classification/
geographic.rs

1//! Module: subnet_catalog::model::classification::geographic
2//!
3//! Defines stable geographic-scope labels used by catalog data.
4
5use serde::{Deserialize, Serialize};
6use std::str::FromStr;
7
8///
9/// GeographicScope
10///
11/// Geographic scope classification for a subnet.
12///
13
14#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
15#[serde(rename_all = "snake_case")]
16pub enum GeographicScope {
17    /// Global subnet scope.
18    Global,
19    /// European subnet scope.
20    Europe,
21    /// Unknown or unclassified geographic scope.
22    Unknown,
23}
24
25impl GeographicScope {
26    /// Returns the stable snake_case value used in CLI filters and text output.
27    #[must_use]
28    pub const fn as_str(self) -> &'static str {
29        match self {
30            Self::Global => "global",
31            Self::Europe => "europe",
32            Self::Unknown => "unknown",
33        }
34    }
35}
36
37impl FromStr for GeographicScope {
38    type Err = String;
39
40    fn from_str(value: &str) -> Result<Self, Self::Err> {
41        match value {
42            "global" => Ok(Self::Global),
43            "europe" => Ok(Self::Europe),
44            "unknown" => Ok(Self::Unknown),
45            other => Err(format!(
46                "invalid value {other}; use global, europe, or unknown"
47            )),
48        }
49    }
50}