Skip to main content

macroonz_compiler/kind/
type_contract.rs

1//! The compiler-owned roster contracts and how a disposition-set completion refusal reads.
2
3use super::types::{
4    Answer, CanonicalContent, Destination, DispositionSetError, NoQuestions, Question, Role,
5    SoleRole,
6};
7use crate::identity::encode_bytes;
8use core::fmt;
9
10impl CanonicalContent for () {
11    fn encode_content_into(&self, _into: &mut Vec<u8>) {}
12}
13
14impl CanonicalContent for &'static str {
15    fn encode_content_into(&self, into: &mut Vec<u8>) {
16        encode_bytes(self.as_bytes(), into);
17    }
18}
19
20impl Role for SoleRole {
21    const ALL: &'static [Self] = &[Self::Sole];
22
23    fn name(self) -> &'static str {
24        "sole"
25    }
26
27    fn destination(self) -> Destination {
28        Destination::DeclarationSite
29    }
30}
31
32impl Question for NoQuestions {
33    const ALL: &'static [Self] = &[];
34
35    type Answer = Self;
36
37    fn name(self) -> &'static str {
38        match self {}
39    }
40}
41
42impl Answer for NoQuestions {
43    type Question = Self;
44
45    fn question(&self) -> Self {
46        match *self {}
47    }
48
49    fn encode_into(&self, _into: &mut Vec<u8>) {
50        match *self {}
51    }
52
53    fn human(&self) -> String {
54        match *self {}
55    }
56}
57
58impl fmt::Display for DispositionSetError {
59    fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
60        match self {
61            Self::CountMismatch { expected, observed } => write!(
62                into,
63                "the kind set declares {expected} names but its disposition record surrendered {observed} rows"
64            ),
65            Self::KindMismatch { expected, observed } => write!(
66                into,
67                "the kind set declares `{expected}` at this position but its disposition record surrendered `{observed}`"
68            ),
69        }
70    }
71}
72
73impl core::error::Error for DispositionSetError {}