coil_template/model/
tokens.rs1use super::*;
2
3#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub struct TemplateNamespace(String);
5
6impl TemplateNamespace {
7 pub fn new(value: impl Into<String>) -> Result<Self, TemplateModelError> {
8 Ok(Self(validate_token("template_namespace", value.into())?))
9 }
10
11 pub fn as_str(&self) -> &str {
12 &self.0
13 }
14}
15
16impl fmt::Display for TemplateNamespace {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 f.write_str(&self.0)
19 }
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
23pub struct TemplateName(String);
24
25impl TemplateName {
26 pub fn new(value: impl Into<String>) -> Result<Self, TemplateModelError> {
27 Ok(Self(validate_token("template_name", value.into())?))
28 }
29
30 pub fn as_str(&self) -> &str {
31 &self.0
32 }
33}
34
35impl fmt::Display for TemplateName {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 f.write_str(&self.0)
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
42pub struct SlotName(String);
43
44impl SlotName {
45 pub fn new(value: impl Into<String>) -> Result<Self, TemplateModelError> {
46 Ok(Self(validate_token("slot_name", value.into())?))
47 }
48
49 pub fn as_str(&self) -> &str {
50 &self.0
51 }
52}
53
54impl fmt::Display for SlotName {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 f.write_str(&self.0)
57 }
58}
59
60#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
61pub struct TemplateKey {
62 pub namespace: TemplateNamespace,
63 pub name: TemplateName,
64}
65
66impl TemplateKey {
67 pub fn new(namespace: TemplateNamespace, name: TemplateName) -> Self {
68 Self { namespace, name }
69 }
70}
71
72impl fmt::Display for TemplateKey {
73 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 write!(f, "{}::{}", self.namespace, self.name)
75 }
76}