1use alloc::string::String;
2use alloc::vec::Vec;
3use core::fmt;
4
5pub trait Context {
7 fn get(&mut self, key: &str) -> Result<Option<Tree>, ContextError>;
9
10 fn set(&mut self, key: &str, value: Tree) -> Result<bool, ContextError>;
12
13 fn delete(&mut self, key: &str) -> Result<bool, ContextError>;
15
16 fn exists(&mut self, key: &str) -> Result<bool, ContextError>;
18}
19
20#[derive(Debug, PartialEq, Clone)]
22pub enum Tree {
23 Scalar(Vec<u8>),
24 Sequence(Vec<Tree>),
25 Mapping(Vec<(Vec<u8>, Tree)>),
26 Null,
27}
28
29#[derive(Debug, PartialEq)]
33pub enum DslError {
34 FileNotFound(String),
35 AmbiguousFile(String),
36 ParseError(String),
37 LimitExceeded(String),
39}
40
41impl fmt::Display for DslError {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match self {
44 DslError::FileNotFound(msg) => write!(f, "FileNotFound: {}", msg),
45 DslError::AmbiguousFile(msg) => write!(f, "AmbiguousFile: {}", msg),
46 DslError::ParseError(msg) => write!(f, "ParseError: {}", msg),
47 DslError::LimitExceeded(msg) => write!(f, "LimitExceeded: {}", msg),
48 }
49 }
50}
51
52#[derive(Debug, PartialEq)]
54pub enum LoadError {
55 ClientNotFound(String),
57 ConfigMissing(String),
59 NotFound(String),
61 ParseError(String),
63}
64
65impl fmt::Display for LoadError {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 match self {
68 LoadError::ClientNotFound(msg) => write!(f, "ClientNotFound: {}", msg),
69 LoadError::ConfigMissing(msg) => write!(f, "ConfigMissing: {}", msg),
70 LoadError::NotFound(msg) => write!(f, "NotFound: {}", msg),
71 LoadError::ParseError(msg) => write!(f, "ParseError: {}", msg),
72 }
73 }
74}
75
76#[derive(Debug, PartialEq)]
78pub enum StoreError {
79 ClientNotFound(String),
81 ConfigMissing(String),
83 SerializeError(String),
85}
86
87impl fmt::Display for StoreError {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89 match self {
90 StoreError::ClientNotFound(msg) => write!(f, "ClientNotFound: {}", msg),
91 StoreError::ConfigMissing(msg) => write!(f, "ConfigMissing: {}", msg),
92 StoreError::SerializeError(msg) => write!(f, "SerializeError: {}", msg),
93 }
94 }
95}
96
97#[derive(Debug, PartialEq)]
99pub enum ContextError {
100 ParseFailed(String),
101 KeyNotFound(String),
102 RecursionLimitExceeded,
103 StoreFailed(StoreError),
104 LoadFailed(LoadError),
105}
106
107impl fmt::Display for ContextError {
108 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109 match self {
110 ContextError::ParseFailed(msg) => write!(f, "ParseFailed: {}", msg),
111 ContextError::KeyNotFound(msg) => write!(f, "KeyNotFound: {}", msg),
112 ContextError::RecursionLimitExceeded => write!(f, "RecursionLimitExceeded"),
113 ContextError::StoreFailed(e) => write!(f, "StoreFailed: {}", e),
114 ContextError::LoadFailed(e) => write!(f, "LoadFailed: {}", e),
115 }
116 }
117}