1mod boxed;
2mod btreemap;
3#[cfg(feature = "std")]
4mod hashmap;
5mod option;
6mod scalar;
7mod vec;
8
9use alloc::collections::{BTreeMap, VecDeque};
10use alloc::vec::Vec;
11
12use crate::cowstr::CowStr;
13use crate::{DecodeError, ESExpr, ESExprTagSet};
14
15pub trait ESExprEncodedEq {
17 fn is_encoded_eq(&self, other: &Self) -> bool;
19}
20
21pub trait ESExprCodec<'a>: ESExprEncodedEq + Sized + 'a {
23 const TAGS: ESExprTagSet;
25
26 fn encode_esexpr(&'a self) -> ESExpr<'a>;
28
29 fn decode_esexpr(expr: ESExpr<'a>) -> Result<Self, DecodeError>;
34}
35
36pub trait ESExprOptionalFieldCodec<'a>: ESExprEncodedEq + Sized + 'a {
38 type Element: ESExprCodec<'a> + 'a;
40
41 fn encode_optional_field(&'a self) -> Option<ESExpr<'a>>;
43
44 fn decode_optional_field(value: Option<ESExpr<'a>>) -> Result<Self, DecodeError>;
49}
50
51pub trait ESExprVarArgCodec<'a>: ESExprEncodedEq + Sized + 'a {
53 type Element: ESExprCodec<'a> + 'a;
55
56 fn encode_vararg_element(&'a self, args: &mut Vec<ESExpr<'a>>);
58
59 fn decode_vararg_element(
64 args: &mut VecDeque<ESExpr<'a>>,
65 constructor_name: &str,
66 start_index: &mut usize,
67 ) -> Result<Self, DecodeError>;
68}
69
70pub trait ESExprDictCodec<'a>
72where
73 Self: Sized + 'a,
74{
75 type Element: ESExprCodec<'a> + 'a;
77
78 fn encode_dict_element(&'a self, kwargs: &mut BTreeMap<CowStr<'a>, ESExpr<'a>>);
80
81 fn decode_dict_element(
86 kwargs: &mut BTreeMap<CowStr<'a>, ESExpr<'a>>,
87 constructor_name: &str,
88 ) -> Result<Self, DecodeError>;
89}