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
27impl SubnetKind {
28 #[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 #[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 #[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}