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 serde::{Deserialize, Serialize};
8use std::fmt::{self, Display};
9
10///
11/// BuildNetwork
12///
13/// Identifies the environment the canister believes it runs in.
14/// Owned by ids and consumed by build-network config and access checks.
15///
16
17#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
18pub enum BuildNetwork {
19    Ic,
20    Local,
21}
22
23impl BuildNetwork {
24    /// Return the stable build-network label.
25    #[must_use]
26    pub const fn as_str(self) -> &'static str {
27        match self {
28            Self::Ic => "ic",
29            Self::Local => "local",
30        }
31    }
32}
33
34impl Display for BuildNetwork {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        f.write_str(self.as_str())
37    }
38}