/rust/registry/src/index.crates.io-1949cf8c6b5b557f/serde_buf-0.1.2/src/ser.rs
Line | Count | Source |
1 | | use core::{cmp, fmt, marker::PhantomData}; |
2 | | |
3 | | use alloc::{boxed::Box, string::ToString, vec::Vec}; |
4 | | use serde_core::{ |
5 | | ser::{ |
6 | | self, Error as _, SerializeMap as _, SerializeSeq as _, SerializeStruct as _, |
7 | | SerializeStructVariant as _, SerializeTuple as _, SerializeTupleStruct as _, |
8 | | SerializeTupleVariant as _, |
9 | | }, |
10 | | Serialize, |
11 | | }; |
12 | | |
13 | | use crate::{Error, Owned, Ref, Value}; |
14 | | |
15 | | impl<'a> Serialize for Ref<'a> { |
16 | 0 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
17 | 0 | where |
18 | 0 | S: serde_core::Serializer, |
19 | | { |
20 | 0 | self.0.serialize(serializer) |
21 | 0 | } |
22 | | } |
23 | | |
24 | | impl Serialize for Owned { |
25 | 0 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
26 | 0 | where |
27 | 0 | S: serde_core::Serializer, |
28 | | { |
29 | 0 | self.0.serialize(serializer) |
30 | 0 | } Unexecuted instantiation: <serde_buf::Owned as serde_core::ser::Serialize>::serialize::<erased_serde::ser::MakeSerializer<&mut dyn erased_serde::ser::Serializer>> Unexecuted instantiation: <serde_buf::Owned as serde_core::ser::Serialize>::serialize::<_> |
31 | | } |
32 | | |
33 | | impl<'a> Serialize for Value<'a> { |
34 | 0 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
35 | 0 | where |
36 | 0 | S: serde_core::Serializer, |
37 | | { |
38 | 0 | match *self { |
39 | 0 | Value::Unit => serializer.serialize_unit(), |
40 | 0 | Value::U8(v) => serializer.serialize_u8(v), |
41 | 0 | Value::U16(v) => serializer.serialize_u16(v), |
42 | 0 | Value::U32(v) => serializer.serialize_u32(v), |
43 | 0 | Value::U64(v) => serializer.serialize_u64(v), |
44 | 0 | Value::U128(v) => serializer.serialize_u128(v), |
45 | 0 | Value::I8(v) => serializer.serialize_i8(v), |
46 | 0 | Value::I16(v) => serializer.serialize_i16(v), |
47 | 0 | Value::I32(v) => serializer.serialize_i32(v), |
48 | 0 | Value::I64(v) => serializer.serialize_i64(v), |
49 | 0 | Value::I128(v) => serializer.serialize_i128(v), |
50 | 0 | Value::F32(v) => serializer.serialize_f32(v), |
51 | 0 | Value::F64(v) => serializer.serialize_f64(v), |
52 | 0 | Value::Bool(v) => serializer.serialize_bool(v), |
53 | 0 | Value::Char(v) => serializer.serialize_char(v), |
54 | 0 | Value::Str(ref v) => serializer.serialize_str(&v), |
55 | 0 | Value::BorrowedStr(v) => serializer.serialize_str(v), |
56 | 0 | Value::Bytes(ref v) => serializer.serialize_bytes(v), |
57 | 0 | Value::BorrowedBytes(v) => serializer.serialize_bytes(v), |
58 | 0 | Value::None => serializer.serialize_none(), |
59 | 0 | Value::Some(ref v) => serializer.serialize_some(v), |
60 | 0 | Value::UnitStruct { name } => serializer.serialize_unit_struct(name), |
61 | 0 | Value::NewtypeStruct { name, ref value } => { |
62 | 0 | serializer.serialize_newtype_struct(name, value) |
63 | | } |
64 | 0 | Value::Struct { name, ref fields } => { |
65 | 0 | let mut serializer = serializer.serialize_struct(name, fields.len())?; |
66 | | |
67 | 0 | for (name, field) in &**fields { |
68 | 0 | serializer.serialize_field(name, field)?; |
69 | | } |
70 | | |
71 | 0 | serializer.end() |
72 | | } |
73 | 0 | Value::TupleStruct { name, ref fields } => { |
74 | 0 | let mut serializer = serializer.serialize_tuple_struct(name, fields.len())?; |
75 | | |
76 | 0 | for field in &**fields { |
77 | 0 | serializer.serialize_field(field)?; |
78 | | } |
79 | | |
80 | 0 | serializer.end() |
81 | | } |
82 | 0 | Value::Tuple(ref v) => { |
83 | 0 | let mut serializer = serializer.serialize_tuple(v.len())?; |
84 | | |
85 | 0 | for field in &**v { |
86 | 0 | serializer.serialize_element(field)?; |
87 | | } |
88 | | |
89 | 0 | serializer.end() |
90 | | } |
91 | | Value::UnitVariant { |
92 | 0 | name, |
93 | 0 | variant_index, |
94 | 0 | variant, |
95 | 0 | } => serializer.serialize_unit_variant(name, variant_index, variant), |
96 | | Value::NewtypeVariant { |
97 | 0 | name, |
98 | 0 | variant_index, |
99 | 0 | variant, |
100 | 0 | ref value, |
101 | 0 | } => serializer.serialize_newtype_variant(name, variant_index, variant, value), |
102 | | Value::TupleVariant { |
103 | 0 | name, |
104 | 0 | variant_index, |
105 | 0 | variant, |
106 | 0 | ref fields, |
107 | | } => { |
108 | 0 | let mut serializer = serializer.serialize_tuple_variant( |
109 | 0 | name, |
110 | 0 | variant_index, |
111 | 0 | variant, |
112 | 0 | fields.len(), |
113 | 0 | )?; |
114 | | |
115 | 0 | for field in &**fields { |
116 | 0 | serializer.serialize_field(field)?; |
117 | | } |
118 | | |
119 | 0 | serializer.end() |
120 | | } |
121 | | Value::StructVariant { |
122 | 0 | name, |
123 | 0 | variant_index, |
124 | 0 | variant, |
125 | 0 | ref fields, |
126 | | } => { |
127 | 0 | let mut serializer = serializer.serialize_struct_variant( |
128 | 0 | name, |
129 | 0 | variant_index, |
130 | 0 | variant, |
131 | 0 | fields.len(), |
132 | 0 | )?; |
133 | | |
134 | 0 | for (name, field) in &**fields { |
135 | 0 | serializer.serialize_field(name, field)?; |
136 | | } |
137 | | |
138 | 0 | serializer.end() |
139 | | } |
140 | 0 | Value::Seq(ref v) => { |
141 | 0 | let mut serializer = serializer.serialize_seq(Some(v.len()))?; |
142 | | |
143 | 0 | for field in &**v { |
144 | 0 | serializer.serialize_element(field)?; |
145 | | } |
146 | | |
147 | 0 | serializer.end() |
148 | | } |
149 | 0 | Value::Map(ref v) => { |
150 | 0 | let mut serializer = serializer.serialize_map(Some(v.len()))?; |
151 | | |
152 | 0 | for (key, value) in &**v { |
153 | 0 | serializer.serialize_entry(key, value)?; |
154 | | } |
155 | | |
156 | 0 | serializer.end() |
157 | | } |
158 | | } |
159 | 0 | } Unexecuted instantiation: <serde_buf::Value as serde_core::ser::Serialize>::serialize::<erased_serde::ser::MakeSerializer<&mut dyn erased_serde::ser::Serializer>> Unexecuted instantiation: <serde_buf::Value as serde_core::ser::Serialize>::serialize::<_> |
160 | | } |
161 | | |
162 | | impl ser::Error for Error { |
163 | 0 | fn custom<T>(msg: T) -> Self |
164 | 0 | where |
165 | 0 | T: fmt::Display, |
166 | | { |
167 | 0 | Error(msg.to_string()) |
168 | 0 | } Unexecuted instantiation: <serde_buf::Error as serde_core::ser::Error>::custom::<alloc::boxed::Box<alloc::string::String>> Unexecuted instantiation: <serde_buf::Error as serde_core::ser::Error>::custom::<&str> |
169 | | } |
170 | | |
171 | | /** |
172 | | A serializer that produces [`Owned`] buffers from an arbitrary [`serde_core::Serialize`]. |
173 | | */ |
174 | | pub struct Serializer(PhantomData<()>); |
175 | | |
176 | | impl Serializer { |
177 | | /** |
178 | | Create a new serializer for an [`Owned`] buffer. |
179 | | */ |
180 | 0 | pub fn new() -> Self { |
181 | 0 | Serializer(PhantomData) |
182 | 0 | } |
183 | | } |
184 | | |
185 | | pub struct SerializeSeq { |
186 | | fields: Vec<Value<'static>>, |
187 | | } |
188 | | |
189 | | pub struct SerializeTuple { |
190 | | fields: Vec<Value<'static>>, |
191 | | } |
192 | | |
193 | | pub struct SerializeTupleStruct { |
194 | | name: &'static str, |
195 | | fields: Vec<Value<'static>>, |
196 | | } |
197 | | |
198 | | pub struct SerializeTupleVariant { |
199 | | name: &'static str, |
200 | | variant_index: u32, |
201 | | variant: &'static str, |
202 | | fields: Vec<Value<'static>>, |
203 | | } |
204 | | |
205 | | pub struct SerializeMap { |
206 | | key: Option<Value<'static>>, |
207 | | fields: Vec<(Value<'static>, Value<'static>)>, |
208 | | } |
209 | | |
210 | | pub struct SerializeStruct { |
211 | | name: &'static str, |
212 | | fields: Vec<(&'static str, Value<'static>)>, |
213 | | } |
214 | | |
215 | | /** |
216 | | A serializer that produces [`Owned`] buffers from struct variants. |
217 | | */ |
218 | | pub struct SerializeStructVariant { |
219 | | name: &'static str, |
220 | | variant_index: u32, |
221 | | variant: &'static str, |
222 | | fields: Vec<(&'static str, Value<'static>)>, |
223 | | } |
224 | | |
225 | | impl serde_core::Serializer for Serializer { |
226 | | type Ok = Owned; |
227 | | type Error = Error; |
228 | | type SerializeSeq = SerializeSeq; |
229 | | type SerializeTuple = SerializeTuple; |
230 | | type SerializeTupleStruct = SerializeTupleStruct; |
231 | | type SerializeTupleVariant = SerializeTupleVariant; |
232 | | type SerializeMap = SerializeMap; |
233 | | type SerializeStruct = SerializeStruct; |
234 | | type SerializeStructVariant = SerializeStructVariant; |
235 | | |
236 | 0 | fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> { |
237 | 0 | Ok(Owned(Value::Bool(v))) |
238 | 0 | } |
239 | | |
240 | 0 | fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> { |
241 | 0 | Ok(Owned(Value::I8(v))) |
242 | 0 | } |
243 | | |
244 | 0 | fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> { |
245 | 0 | Ok(Owned(Value::I16(v))) |
246 | 0 | } |
247 | | |
248 | 0 | fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> { |
249 | 0 | Ok(Owned(Value::I32(v))) |
250 | 0 | } |
251 | | |
252 | 0 | fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> { |
253 | 0 | Ok(Owned(Value::I64(v))) |
254 | 0 | } |
255 | | |
256 | 0 | fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> { |
257 | 0 | Ok(Owned(Value::I128(v))) |
258 | 0 | } |
259 | | |
260 | 0 | fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> { |
261 | 0 | Ok(Owned(Value::U8(v))) |
262 | 0 | } |
263 | | |
264 | 0 | fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> { |
265 | 0 | Ok(Owned(Value::U16(v))) |
266 | 0 | } |
267 | | |
268 | 0 | fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> { |
269 | 0 | Ok(Owned(Value::U32(v))) |
270 | 0 | } |
271 | | |
272 | 0 | fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> { |
273 | 0 | Ok(Owned(Value::U64(v))) |
274 | 0 | } |
275 | | |
276 | 0 | fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> { |
277 | 0 | Ok(Owned(Value::U128(v))) |
278 | 0 | } |
279 | | |
280 | 0 | fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> { |
281 | 0 | Ok(Owned(Value::F32(v))) |
282 | 0 | } |
283 | | |
284 | 0 | fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> { |
285 | 0 | Ok(Owned(Value::F64(v))) |
286 | 0 | } |
287 | | |
288 | 0 | fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> { |
289 | 0 | Ok(Owned(Value::Char(v))) |
290 | 0 | } |
291 | | |
292 | 0 | fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> { |
293 | 0 | Ok(Owned(Value::Str(v.into()))) |
294 | 0 | } |
295 | | |
296 | 0 | fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> { |
297 | 0 | Ok(Owned(Value::Bytes(v.into()))) |
298 | 0 | } |
299 | | |
300 | 0 | fn serialize_none(self) -> Result<Self::Ok, Self::Error> { |
301 | 0 | Ok(Owned(Value::None)) |
302 | 0 | } |
303 | | |
304 | 0 | fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error> |
305 | 0 | where |
306 | 0 | T: Serialize, |
307 | | { |
308 | 0 | Ok(Owned(Value::Some(Box::new( |
309 | 0 | value.serialize(Serializer::new())?.0, |
310 | | )))) |
311 | 0 | } Unexecuted instantiation: <serde_buf::ser::Serializer as serde_core::ser::Serializer>::serialize_some::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::Serializer as serde_core::ser::Serializer>::serialize_some::<_> |
312 | | |
313 | 0 | fn serialize_unit(self) -> Result<Self::Ok, Self::Error> { |
314 | 0 | Ok(Owned(Value::Unit)) |
315 | 0 | } |
316 | | |
317 | 0 | fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> { |
318 | 0 | Ok(Owned(Value::UnitStruct { name })) |
319 | 0 | } |
320 | | |
321 | 0 | fn serialize_unit_variant( |
322 | 0 | self, |
323 | 0 | name: &'static str, |
324 | 0 | variant_index: u32, |
325 | 0 | variant: &'static str, |
326 | 0 | ) -> Result<Self::Ok, Self::Error> { |
327 | 0 | Ok(Owned(Value::UnitVariant { |
328 | 0 | name, |
329 | 0 | variant_index, |
330 | 0 | variant, |
331 | 0 | })) |
332 | 0 | } |
333 | | |
334 | 0 | fn serialize_newtype_struct<T: ?Sized>( |
335 | 0 | self, |
336 | 0 | name: &'static str, |
337 | 0 | value: &T, |
338 | 0 | ) -> Result<Self::Ok, Self::Error> |
339 | 0 | where |
340 | 0 | T: Serialize, |
341 | | { |
342 | | Ok(Owned(Value::NewtypeStruct { |
343 | 0 | name, |
344 | 0 | value: Box::new(value.serialize(Serializer::new())?.0), |
345 | | })) |
346 | 0 | } Unexecuted instantiation: <serde_buf::ser::Serializer as serde_core::ser::Serializer>::serialize_newtype_struct::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::Serializer as serde_core::ser::Serializer>::serialize_newtype_struct::<_> |
347 | | |
348 | 0 | fn serialize_newtype_variant<T: ?Sized>( |
349 | 0 | self, |
350 | 0 | name: &'static str, |
351 | 0 | variant_index: u32, |
352 | 0 | variant: &'static str, |
353 | 0 | value: &T, |
354 | 0 | ) -> Result<Self::Ok, Self::Error> |
355 | 0 | where |
356 | 0 | T: Serialize, |
357 | | { |
358 | | Ok(Owned(Value::NewtypeVariant { |
359 | 0 | name, |
360 | 0 | variant_index, |
361 | 0 | variant, |
362 | 0 | value: Box::new(value.serialize(Serializer::new())?.0), |
363 | | })) |
364 | 0 | } Unexecuted instantiation: <serde_buf::ser::Serializer as serde_core::ser::Serializer>::serialize_newtype_variant::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::Serializer as serde_core::ser::Serializer>::serialize_newtype_variant::<_> |
365 | | |
366 | 0 | fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> { |
367 | 0 | Ok(SerializeSeq { |
368 | 0 | fields: Vec::with_capacity(cmp::min(len.unwrap_or(0), 32)), |
369 | 0 | }) |
370 | 0 | } |
371 | | |
372 | 0 | fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> { |
373 | 0 | Ok(SerializeTuple { |
374 | 0 | fields: Vec::with_capacity(cmp::min(len, 32)), |
375 | 0 | }) |
376 | 0 | } |
377 | | |
378 | 0 | fn serialize_tuple_struct( |
379 | 0 | self, |
380 | 0 | name: &'static str, |
381 | 0 | len: usize, |
382 | 0 | ) -> Result<Self::SerializeTupleStruct, Self::Error> { |
383 | 0 | Ok(SerializeTupleStruct { |
384 | 0 | name, |
385 | 0 | fields: Vec::with_capacity(cmp::min(len, 32)), |
386 | 0 | }) |
387 | 0 | } |
388 | | |
389 | 0 | fn serialize_tuple_variant( |
390 | 0 | self, |
391 | 0 | name: &'static str, |
392 | 0 | variant_index: u32, |
393 | 0 | variant: &'static str, |
394 | 0 | len: usize, |
395 | 0 | ) -> Result<Self::SerializeTupleVariant, Self::Error> { |
396 | 0 | Ok(SerializeTupleVariant { |
397 | 0 | name, |
398 | 0 | variant_index, |
399 | 0 | variant, |
400 | 0 | fields: Vec::with_capacity(cmp::min(len, 32)), |
401 | 0 | }) |
402 | 0 | } |
403 | | |
404 | 0 | fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> { |
405 | 0 | Ok(SerializeMap { |
406 | 0 | key: None, |
407 | 0 | fields: Vec::with_capacity(cmp::min(len.unwrap_or(0), 32)), |
408 | 0 | }) |
409 | 0 | } |
410 | | |
411 | 0 | fn serialize_struct( |
412 | 0 | self, |
413 | 0 | name: &'static str, |
414 | 0 | len: usize, |
415 | 0 | ) -> Result<Self::SerializeStruct, Self::Error> { |
416 | 0 | Ok(SerializeStruct { |
417 | 0 | name, |
418 | 0 | fields: Vec::with_capacity(cmp::min(len, 32)), |
419 | 0 | }) |
420 | 0 | } |
421 | | |
422 | 0 | fn serialize_struct_variant( |
423 | 0 | self, |
424 | 0 | name: &'static str, |
425 | 0 | variant_index: u32, |
426 | 0 | variant: &'static str, |
427 | 0 | len: usize, |
428 | 0 | ) -> Result<Self::SerializeStructVariant, Self::Error> { |
429 | 0 | Ok(SerializeStructVariant { |
430 | 0 | name, |
431 | 0 | variant_index, |
432 | 0 | variant, |
433 | 0 | fields: Vec::with_capacity(cmp::min(len, 32)), |
434 | 0 | }) |
435 | 0 | } |
436 | | } |
437 | | |
438 | | impl ser::SerializeSeq for SerializeSeq { |
439 | | type Ok = Owned; |
440 | | type Error = Error; |
441 | | |
442 | 0 | fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error> |
443 | 0 | where |
444 | 0 | T: Serialize, |
445 | | { |
446 | 0 | self.fields.push(value.serialize(Serializer::new())?.0); |
447 | | |
448 | 0 | Ok(()) |
449 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeSeq as serde_core::ser::SerializeSeq>::serialize_element::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeSeq as serde_core::ser::SerializeSeq>::serialize_element::<_> |
450 | | |
451 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
452 | 0 | Ok(Owned(Value::Seq(self.fields.into_boxed_slice()))) |
453 | 0 | } |
454 | | } |
455 | | |
456 | | impl ser::SerializeMap for SerializeMap { |
457 | | type Ok = Owned; |
458 | | type Error = Error; |
459 | | |
460 | 0 | fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error> |
461 | 0 | where |
462 | 0 | T: Serialize, |
463 | | { |
464 | 0 | if self.key.is_some() { |
465 | 0 | return Err(Error::custom("missing map value")); |
466 | 0 | } |
467 | | |
468 | 0 | self.key = Some(key.serialize(Serializer::new())?.0); |
469 | | |
470 | 0 | Ok(()) |
471 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_key::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_key::<_> |
472 | | |
473 | 0 | fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error> |
474 | 0 | where |
475 | 0 | T: Serialize, |
476 | | { |
477 | 0 | let key = self |
478 | 0 | .key |
479 | 0 | .take() |
480 | 0 | .ok_or_else(|| Error::custom("missing map key"))?;Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_value::<dyn erased_serde::ser::Serialize>::{closure#0}Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_value::<_>::{closure#0} |
481 | 0 | let value = value.serialize(Serializer::new())?.0; |
482 | | |
483 | 0 | self.fields.push((key, value)); |
484 | | |
485 | 0 | Ok(()) |
486 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_value::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_value::<_> |
487 | | |
488 | 0 | fn serialize_entry<K: ?Sized, V: ?Sized>( |
489 | 0 | &mut self, |
490 | 0 | key: &K, |
491 | 0 | value: &V, |
492 | 0 | ) -> Result<(), Self::Error> |
493 | 0 | where |
494 | 0 | K: Serialize, |
495 | 0 | V: Serialize, |
496 | | { |
497 | 0 | if self.key.is_some() { |
498 | 0 | return Err(Error::custom("missing map value")); |
499 | 0 | } |
500 | | |
501 | 0 | let key = key.serialize(Serializer::new())?.0; |
502 | 0 | let value = value.serialize(Serializer::new())?.0; |
503 | | |
504 | 0 | self.fields.push((key, value)); |
505 | | |
506 | 0 | Ok(()) |
507 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_entry::<dyn erased_serde::ser::Serialize, dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeMap as serde_core::ser::SerializeMap>::serialize_entry::<_, _> |
508 | | |
509 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
510 | 0 | if self.key.is_some() { |
511 | 0 | return Err(Error::custom("missing map value")); |
512 | 0 | } |
513 | | |
514 | 0 | Ok(Owned(Value::Map(self.fields.into_boxed_slice()))) |
515 | 0 | } |
516 | | } |
517 | | |
518 | | impl ser::SerializeStruct for SerializeStruct { |
519 | | type Ok = Owned; |
520 | | type Error = Error; |
521 | | |
522 | 0 | fn serialize_field<T: ?Sized>( |
523 | 0 | &mut self, |
524 | 0 | key: &'static str, |
525 | 0 | value: &T, |
526 | 0 | ) -> Result<(), Self::Error> |
527 | 0 | where |
528 | 0 | T: Serialize, |
529 | | { |
530 | 0 | self.fields |
531 | 0 | .push((key, value.serialize(Serializer::new())?.0)); |
532 | | |
533 | 0 | Ok(()) |
534 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeStruct as serde_core::ser::SerializeStruct>::serialize_field::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeStruct as serde_core::ser::SerializeStruct>::serialize_field::<_> |
535 | | |
536 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
537 | 0 | Ok(Owned(Value::Struct { |
538 | 0 | name: self.name, |
539 | 0 | fields: self.fields.into_boxed_slice(), |
540 | 0 | })) |
541 | 0 | } |
542 | | } |
543 | | |
544 | | impl ser::SerializeStructVariant for SerializeStructVariant { |
545 | | type Ok = Owned; |
546 | | type Error = Error; |
547 | | |
548 | 0 | fn serialize_field<T: ?Sized>( |
549 | 0 | &mut self, |
550 | 0 | key: &'static str, |
551 | 0 | value: &T, |
552 | 0 | ) -> Result<(), Self::Error> |
553 | 0 | where |
554 | 0 | T: Serialize, |
555 | | { |
556 | 0 | self.fields |
557 | 0 | .push((key, value.serialize(Serializer::new())?.0)); |
558 | | |
559 | 0 | Ok(()) |
560 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeStructVariant as serde_core::ser::SerializeStructVariant>::serialize_field::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeStructVariant as serde_core::ser::SerializeStructVariant>::serialize_field::<_> |
561 | | |
562 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
563 | 0 | Ok(Owned(Value::StructVariant { |
564 | 0 | name: self.name, |
565 | 0 | variant_index: self.variant_index, |
566 | 0 | variant: self.variant, |
567 | 0 | fields: self.fields.into_boxed_slice(), |
568 | 0 | })) |
569 | 0 | } |
570 | | } |
571 | | |
572 | | impl ser::SerializeTuple for SerializeTuple { |
573 | | type Ok = Owned; |
574 | | type Error = Error; |
575 | | |
576 | 0 | fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error> |
577 | 0 | where |
578 | 0 | T: Serialize, |
579 | | { |
580 | 0 | self.fields.push(value.serialize(Serializer::new())?.0); |
581 | | |
582 | 0 | Ok(()) |
583 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeTuple as serde_core::ser::SerializeTuple>::serialize_element::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeTuple as serde_core::ser::SerializeTuple>::serialize_element::<_> |
584 | | |
585 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
586 | 0 | Ok(Owned(Value::Tuple(self.fields.into_boxed_slice()))) |
587 | 0 | } |
588 | | } |
589 | | |
590 | | impl ser::SerializeTupleStruct for SerializeTupleStruct { |
591 | | type Ok = Owned; |
592 | | type Error = Error; |
593 | | |
594 | 0 | fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error> |
595 | 0 | where |
596 | 0 | T: Serialize, |
597 | | { |
598 | 0 | self.fields.push(value.serialize(Serializer::new())?.0); |
599 | | |
600 | 0 | Ok(()) |
601 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeTupleStruct as serde_core::ser::SerializeTupleStruct>::serialize_field::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeTupleStruct as serde_core::ser::SerializeTupleStruct>::serialize_field::<_> |
602 | | |
603 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
604 | 0 | Ok(Owned(Value::TupleStruct { |
605 | 0 | name: self.name, |
606 | 0 | fields: self.fields.into_boxed_slice(), |
607 | 0 | })) |
608 | 0 | } |
609 | | } |
610 | | |
611 | | impl ser::SerializeTupleVariant for SerializeTupleVariant { |
612 | | type Ok = Owned; |
613 | | type Error = Error; |
614 | | |
615 | 0 | fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error> |
616 | 0 | where |
617 | 0 | T: Serialize, |
618 | | { |
619 | 0 | self.fields.push(value.serialize(Serializer::new())?.0); |
620 | | |
621 | 0 | Ok(()) |
622 | 0 | } Unexecuted instantiation: <serde_buf::ser::SerializeTupleVariant as serde_core::ser::SerializeTupleVariant>::serialize_field::<dyn erased_serde::ser::Serialize> Unexecuted instantiation: <serde_buf::ser::SerializeTupleVariant as serde_core::ser::SerializeTupleVariant>::serialize_field::<_> |
623 | | |
624 | 0 | fn end(self) -> Result<Self::Ok, Self::Error> { |
625 | 0 | Ok(Owned(Value::TupleVariant { |
626 | 0 | name: self.name, |
627 | 0 | variant_index: self.variant_index, |
628 | 0 | variant: self.variant, |
629 | 0 | fields: self.fields.into_boxed_slice(), |
630 | 0 | })) |
631 | 0 | } |
632 | | } |