Skip to main content

canic_core/ids/
network.rs

1//! Module: ids::network
2//!
3//! Responsibility: build network identifiers.
4//! Does not own: environment detection or deployment selection.
5//! Boundary: exposes the network label a canister believes it runs under.
6
7use crate::cdk::candid::CandidType;
8use serde::{Deserialize, Serialize};
9use std::fmt::{self, Display};
10
11///
12/// BuildNetwork
13///
14/// Identifies the environment the canister believes it runs in.
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    Ic,
21    Local,
22}
23
24impl BuildNetwork {
25    /// Return the stable build-network label.
26    #[must_use]
27    pub const fn as_str(self) -> &'static str {
28        match self {
29            Self::Ic => "ic",
30            Self::Local => "local",
31        }
32    }
33}
34
35impl Display for BuildNetwork {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        f.write_str(self.as_str())
38    }
39}