1use candid::CandidType;
8use serde::{Deserialize, Serialize};
9use std::fmt;
10
11#[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}