1pub trait SerializerConfig: sealed::SerializerConfig {}
8
9impl<T: sealed::SerializerConfig> SerializerConfig for T {}
10
11pub(crate) mod sealed {
12 use crate::config::BytesMode;
13
14 pub trait SerializerConfig: Copy {
19 fn is_human_readable(&self) -> bool;
22
23 fn is_named(&self) -> bool;
25 fn bytes(&self) -> BytesMode;
26 }
27}
28
29#[derive(Copy, Clone, Debug)]
30pub(crate) struct RuntimeConfig {
31 pub(crate) is_human_readable: bool,
32 pub(crate) is_named: bool,
33 pub(crate) bytes: BytesMode,
34}
35
36#[non_exhaustive]
41#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
42pub enum BytesMode {
43 #[default]
46 Normal,
47 ForceIterables,
54 ForceAll,
57}
58
59impl RuntimeConfig {
60 pub(crate) fn new(other: impl sealed::SerializerConfig) -> Self {
61 Self {
62 is_human_readable: other.is_human_readable(),
63 is_named: other.is_named(),
64 bytes: other.bytes(),
65 }
66 }
67}
68
69impl sealed::SerializerConfig for RuntimeConfig {
70 #[inline]
71 fn is_human_readable(&self) -> bool {
72 self.is_human_readable
73 }
74
75 #[inline]
76 fn is_named(&self) -> bool {
77 self.is_named
78 }
79
80 #[inline]
81 fn bytes(&self) -> BytesMode {
82 self.bytes
83 }
84}
85
86#[derive(Copy, Clone, Debug)]
95pub struct DefaultConfig;
96
97impl sealed::SerializerConfig for DefaultConfig {
98 #[inline(always)]
99 fn is_named(&self) -> bool {
100 false
101 }
102
103 #[inline(always)]
104 fn is_human_readable(&self) -> bool {
105 false
106 }
107
108 #[inline(always)]
109 fn bytes(&self) -> BytesMode {
110 BytesMode::default()
111 }
112}
113
114#[derive(Copy, Clone, Debug)]
122pub struct StructMapConfig<C>(C);
123
124impl<C> StructMapConfig<C> {
125 #[inline]
127 pub fn new(inner: C) -> Self {
128 StructMapConfig(inner)
129 }
130}
131
132impl<C> sealed::SerializerConfig for StructMapConfig<C>
133where
134 C: sealed::SerializerConfig,
135{
136 #[inline(always)]
137 fn is_named(&self) -> bool {
138 true
139 }
140
141 #[inline(always)]
142 fn is_human_readable(&self) -> bool {
143 self.0.is_human_readable()
144 }
145
146 fn bytes(&self) -> BytesMode {
147 self.0.bytes()
148 }
149}
150
151#[derive(Copy, Clone, Debug)]
154pub struct StructTupleConfig<C>(C);
155
156impl<C> StructTupleConfig<C> {
157 #[inline]
159 pub fn new(inner: C) -> Self {
160 StructTupleConfig(inner)
161 }
162}
163
164impl<C> sealed::SerializerConfig for StructTupleConfig<C>
165where
166 C: sealed::SerializerConfig,
167{
168 #[inline(always)]
169 fn is_named(&self) -> bool {
170 false
171 }
172
173 #[inline(always)]
174 fn is_human_readable(&self) -> bool {
175 self.0.is_human_readable()
176 }
177
178 fn bytes(&self) -> BytesMode {
179 self.0.bytes()
180 }
181}
182
183#[derive(Copy, Clone, Debug)]
186pub struct HumanReadableConfig<C>(C);
187
188impl<C> HumanReadableConfig<C> {
189 #[inline]
191 pub fn new(inner: C) -> Self {
192 Self(inner)
193 }
194}
195
196impl<C> sealed::SerializerConfig for HumanReadableConfig<C>
197where
198 C: sealed::SerializerConfig,
199{
200 #[inline(always)]
201 fn is_named(&self) -> bool {
202 self.0.is_named()
203 }
204
205 #[inline(always)]
206 fn is_human_readable(&self) -> bool {
207 true
208 }
209
210 fn bytes(&self) -> BytesMode {
211 self.0.bytes()
212 }
213}
214
215#[derive(Copy, Clone, Debug)]
218pub struct BinaryConfig<C>(C);
219
220impl<C> BinaryConfig<C> {
221 #[inline(always)]
223 pub fn new(inner: C) -> Self {
224 Self(inner)
225 }
226}
227
228impl<C> sealed::SerializerConfig for BinaryConfig<C>
229where
230 C: sealed::SerializerConfig,
231{
232 #[inline(always)]
233 fn is_named(&self) -> bool {
234 self.0.is_named()
235 }
236
237 #[inline(always)]
238 fn is_human_readable(&self) -> bool {
239 false
240 }
241
242 fn bytes(&self) -> BytesMode {
243 self.0.bytes()
244 }
245}