Skip to main content

ic_query/subnet_catalog/model/classification/
kind.rs

1//! Module: subnet_catalog::model::classification::kind
2//!
3//! Defines stable subnet-kind labels and their default charging meaning.
4
5use serde::{Deserialize, Serialize};
6use std::str::FromStr;
7
8///
9/// SubnetKind
10///
11/// Subnet execution kind from registry or derived catalog classification.
12///
13
14#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
15#[serde(rename_all = "snake_case")]
16pub enum SubnetKind {
17    /// Application subnet.
18    Application,
19    /// Cloud Engine subnet.
20    CloudEngine,
21    /// System subnet.
22    System,
23    /// Unknown or unclassified subnet kind.
24    Unknown,
25}
26
27impl SubnetKind {
28    /// Convert one raw Registry `SubnetType` numeric discriminant.
29    #[must_use]
30    pub const fn from_registry_subnet_type(raw_subnet_type: i32) -> Self {
31        match raw_subnet_type {
32            1 | 4 => Self::Application,
33            2 => Self::System,
34            5 => Self::CloudEngine,
35            _ => Self::Unknown,
36        }
37    }
38
39    /// Returns the stable snake_case value used in CLI filters and text output.
40    #[must_use]
41    pub const fn as_str(self) -> &'static str {
42        match self {
43            Self::Application => "application",
44            Self::CloudEngine => "cloud_engine",
45            Self::System => "system",
46            Self::Unknown => "unknown",
47        }
48    }
49
50    /// Returns whether a subject on this subnet kind normally incurs application charges.
51    #[must_use]
52    pub const fn charges_apply_by_default(self) -> bool {
53        matches!(self, Self::Application | Self::CloudEngine)
54    }
55}
56
57impl FromStr for SubnetKind {
58    type Err = String;
59
60    fn from_str(value: &str) -> Result<Self, Self::Err> {
61        match value {
62            "application" => Ok(Self::Application),
63            "cloud_engine" => Ok(Self::CloudEngine),
64            "system" => Ok(Self::System),
65            "unknown" => Ok(Self::Unknown),
66            other => Err(format!(
67                "invalid value {other}; use application, cloud_engine, system, or unknown"
68            )),
69        }
70    }
71}