ic_query/subnet_catalog/model/classification/
kind.rs1use serde::{Deserialize, Serialize};
2use std::str::FromStr;
3
4#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
8#[serde(rename_all = "snake_case")]
9pub enum SubnetKind {
10 Application,
11 CloudEngine,
12 System,
13 Unknown,
14}
15
16impl SubnetKind {
17 #[must_use]
18 pub const fn as_str(self) -> &'static str {
19 match self {
20 Self::Application => "application",
21 Self::CloudEngine => "cloud_engine",
22 Self::System => "system",
23 Self::Unknown => "unknown",
24 }
25 }
26
27 #[must_use]
28 pub const fn charges_apply_by_default(self) -> bool {
29 matches!(self, Self::Application | Self::CloudEngine)
30 }
31}
32
33impl FromStr for SubnetKind {
34 type Err = String;
35
36 fn from_str(value: &str) -> Result<Self, Self::Err> {
37 match value {
38 "application" => Ok(Self::Application),
39 "cloud_engine" => Ok(Self::CloudEngine),
40 "system" => Ok(Self::System),
41 "unknown" => Ok(Self::Unknown),
42 other => Err(format!(
43 "invalid value {other}; use application, cloud_engine, system, or unknown"
44 )),
45 }
46 }
47}