Skip to main content

canic_core/ids/
app.rs

1//! Module: ids::app
2//!
3//! Responsibility: identify one checked-in App definition.
4//! Does not own: live Fleet identity, deployment labels, or filesystem paths.
5//! Boundary: configuration validation admits the wrapped source name before use.
6
7use candid::CandidType;
8use serde::{Deserialize, Serialize};
9use std::fmt;
10
11///
12/// AppId
13///
14/// Immutable source identity declared by `[app].name`.
15///
16
17#[derive(Clone, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
18#[serde(transparent)]
19pub struct AppId(String);
20
21impl AppId {
22    #[must_use]
23    pub const fn owned(value: String) -> Self {
24        Self(value)
25    }
26
27    #[must_use]
28    pub const fn as_str(&self) -> &str {
29        self.0.as_str()
30    }
31}
32
33impl AsRef<str> for AppId {
34    fn as_ref(&self) -> &str {
35        self.as_str()
36    }
37}
38
39impl fmt::Display for AppId {
40    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
41        formatter.write_str(self.as_str())
42    }
43}
44
45impl CandidType for AppId {
46    fn _ty() -> candid::types::Type {
47        candid::types::TypeInner::Text.into()
48    }
49
50    fn idl_serialize<S>(&self, serializer: S) -> Result<(), S::Error>
51    where
52        S: candid::types::Serializer,
53    {
54        serializer.serialize_text(self.as_str())
55    }
56}
57
58impl From<&str> for AppId {
59    fn from(value: &str) -> Self {
60        Self(value.to_string())
61    }
62}
63
64impl From<String> for AppId {
65    fn from(value: String) -> Self {
66        Self::owned(value)
67    }
68}