ic_query/subnet_catalog/model/classification/
kind.rs1use serde::{Deserialize, Serialize};
6use std::str::FromStr;
7
8#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
15#[serde(rename_all = "snake_case")]
16pub enum SubnetKind {
17 Application,
19 CloudEngine,
21 System,
23 Unknown,
25}
26
27pub(in crate::subnet_catalog) const REGISTRY_SUBNET_KINDS: &[(i32, SubnetKind)] = &[
28 (0, SubnetKind::Unknown),
29 (1, SubnetKind::Application),
30 (2, SubnetKind::System),
31 (4, SubnetKind::Application),
32 (5, SubnetKind::CloudEngine),
33];
34
35impl SubnetKind {
36 #[cfg(feature = "subnet-catalog-host")]
37 pub(in crate::subnet_catalog) const ALL: [Self; 4] = [
38 Self::Application,
39 Self::CloudEngine,
40 Self::System,
41 Self::Unknown,
42 ];
43 #[must_use]
45 pub const fn from_registry_subnet_type(raw_subnet_type: i32) -> Self {
46 let mut index = 0;
47 while index < REGISTRY_SUBNET_KINDS.len() {
48 let (raw, kind) = REGISTRY_SUBNET_KINDS[index];
49 if raw == raw_subnet_type {
50 return kind;
51 }
52 index += 1;
53 }
54 Self::Unknown
55 }
56
57 #[must_use]
59 pub const fn as_str(self) -> &'static str {
60 match self {
61 Self::Application => "application",
62 Self::CloudEngine => "cloud_engine",
63 Self::System => "system",
64 Self::Unknown => "unknown",
65 }
66 }
67
68 #[must_use]
70 pub const fn charges_apply_by_default(self) -> bool {
71 matches!(self, Self::Application | Self::CloudEngine)
72 }
73}
74
75impl FromStr for SubnetKind {
76 type Err = String;
77
78 fn from_str(value: &str) -> Result<Self, Self::Err> {
79 match value {
80 "application" => Ok(Self::Application),
81 "cloud_engine" => Ok(Self::CloudEngine),
82 "system" => Ok(Self::System),
83 "unknown" => Ok(Self::Unknown),
84 other => Err(format!(
85 "invalid value {other}; use application, cloud_engine, system, or unknown"
86 )),
87 }
88 }
89}