Skip to main content

ic_query/subnet_catalog/model/classification/
geographic.rs

1use serde::{Deserialize, Serialize};
2use std::str::FromStr;
3
4///
5/// GeographicScope
6///
7#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
8#[serde(rename_all = "snake_case")]
9pub enum GeographicScope {
10    Global,
11    Europe,
12    Unknown,
13}
14
15impl GeographicScope {
16    #[must_use]
17    pub const fn as_str(self) -> &'static str {
18        match self {
19            Self::Global => "global",
20            Self::Europe => "europe",
21            Self::Unknown => "unknown",
22        }
23    }
24}
25
26impl FromStr for GeographicScope {
27    type Err = String;
28
29    fn from_str(value: &str) -> Result<Self, Self::Err> {
30        match value {
31            "global" => Ok(Self::Global),
32            "europe" => Ok(Self::Europe),
33            "unknown" => Ok(Self::Unknown),
34            other => Err(format!(
35                "invalid value {other}; use global, europe, or unknown"
36            )),
37        }
38    }
39}