Skip to main content

canic_core/ids/build_network/
mod.rs

1//! Module: ids::build_network
2//!
3//! Responsibility: build-network identifiers.
4//! Does not own: ICP environment resolution or deployment selection.
5//! Boundary: exposes the network class baked into a canister artifact.
6
7use crate::cdk::candid::CandidType;
8use serde::{Deserialize, Serialize};
9use std::fmt::{self, Display};
10
11///
12/// BuildNetwork
13///
14/// Identifies the network class the canister was built for.
15/// Owned by ids and consumed by build-network config and access checks.
16///
17
18#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
19pub enum BuildNetwork {
20    #[serde(rename = "ic")]
21    Ic,
22    #[serde(rename = "local")]
23    Local,
24}
25
26impl BuildNetwork {
27    /// Parse the canonical build-network label.
28    #[must_use]
29    pub(crate) fn parse(value: &str) -> Option<Self> {
30        match value {
31            "ic" => Some(Self::Ic),
32            "local" => Some(Self::Local),
33            _ => None,
34        }
35    }
36
37    /// Return the stable build-network label.
38    #[must_use]
39    pub const fn as_str(self) -> &'static str {
40        match self {
41            Self::Ic => "ic",
42            Self::Local => "local",
43        }
44    }
45}
46
47impl Display for BuildNetwork {
48    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49        f.write_str(self.as_str())
50    }
51}