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    /// Returns the stable snake_case value used in CLI filters and text output.
29    #[must_use]
30    pub const fn as_str(self) -> &'static str {
31        match self {
32            Self::Application => "application",
33            Self::CloudEngine => "cloud_engine",
34            Self::System => "system",
35            Self::Unknown => "unknown",
36        }
37    }
38
39    /// Returns whether a subject on this subnet kind normally incurs application charges.
40    #[must_use]
41    pub const fn charges_apply_by_default(self) -> bool {
42        matches!(self, Self::Application | Self::CloudEngine)
43    }
44}
45
46impl FromStr for SubnetKind {
47    type Err = String;
48
49    fn from_str(value: &str) -> Result<Self, Self::Err> {
50        match value {
51            "application" => Ok(Self::Application),
52            "cloud_engine" => Ok(Self::CloudEngine),
53            "system" => Ok(Self::System),
54            "unknown" => Ok(Self::Unknown),
55            other => Err(format!(
56                "invalid value {other}; use application, cloud_engine, system, or unknown"
57            )),
58        }
59    }
60}